-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-17517] Only Initialize specified provider
Code currently tries to initialize multiple providers based on provided config Opts being nil or not. This update ensures that only specified provider is initialized based on ProviderName. This fixes "Failed initializing PKCS11.BCCSP %!s(<nil>)" error when the code complied with PKCS11 or PLUGINS enabled expect configuration to not be nil even when Provider is set to SW. Also adding unit tests. Signed-off-by: Ahmed Sajid <ahmed.sajid@securekey.com>
- Loading branch information
1 parent
defb36c
commit 2bb6415
Showing
4 changed files
with
138 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// +build !pkcs11 | ||
|
||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package factory | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInitFactoriesWithMultipleProviders(t *testing.T) { | ||
// testing SW Provider and ensuring other providers are not initialized | ||
factoriesInitError = nil | ||
|
||
err := initFactories(&FactoryOpts{ | ||
ProviderName: "SW", | ||
SwOpts: &SwOpts{}, | ||
PluginOpts: &PluginOpts{}, | ||
}) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "Failed initializing BCCSP") | ||
assert.NotContains(t, err.Error(), "Failed initializing PLUGIN.BCCSP") | ||
|
||
// testing PLUGIN Provider and ensuring other providers are not initialized | ||
factoriesInitError = nil | ||
|
||
err = initFactories(&FactoryOpts{ | ||
ProviderName: "PLUGIN", | ||
SwOpts: &SwOpts{}, | ||
PluginOpts: &PluginOpts{}, | ||
}) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "Failed initializing PLUGIN.BCCSP") | ||
assert.NotContains(t, err.Error(), "Failed initializing BCCSP") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters