-
Notifications
You must be signed in to change notification settings - Fork 709
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-10097] Support for ecert flag in config.yaml
The same method have been implemented for parsing user identity attribute values from fabric-ca-server-config.yaml what fabric-ca-client already implements. Change-Id: I9acb14e0150bcf41614cfaf7f68e7f6ed825bf57 Signed-off-by: Frank Felhoffer <ffelhoffer@gmail.com> Signed-off-by: Christopher Ferris <chrisfer@us.ibm.com>
- Loading branch information
1 parent
b28fdfd
commit 2697db3
Showing
6 changed files
with
224 additions
and
67 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,91 @@ | ||
/* | ||
Copyright IBM Corp. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package command | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric-ca/lib" | ||
) | ||
|
||
func TestProcessAttributes(t *testing.T) { | ||
// test cases | ||
positiveAttrs := []string{ | ||
"AttrList=peer,orderer,client,user", | ||
"AttrListWithECertAttr=peer,orderer,client,user:ecert", | ||
"AttrTrue=true", | ||
"AttrTrueWithECertAttr=true:ecert", | ||
"AttrFalse=false", | ||
"AttrStar=*", | ||
"AttrStarWithECertAttr=*:ecert", | ||
} | ||
negativeAttrs1 := []string{ | ||
"AttrTrueWithInvalidAttr=true:invalid", | ||
} | ||
negativeAttrs2 := []string{ | ||
"AttrTrueWithDuplicateAttrs=true:ecert:ecert", | ||
} | ||
|
||
clientCfg := lib.ClientConfig{} | ||
|
||
err := processAttributes(positiveAttrs, &clientCfg) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
for _, attr := range clientCfg.ID.Attributes { | ||
switch attr.Name { | ||
case "AttrList": | ||
if attr.Value != "peer,orderer,client,user" || attr.ECert != false { | ||
t.Fatalf("Attr conversion of '%s' failed (value='%s', ecert='%v')", | ||
attr.Name, attr.Value, attr.ECert) | ||
} | ||
case "AttrListWithECertAttr": | ||
if attr.Value != "peer,orderer,client,user" || attr.ECert != true { | ||
t.Fatalf("Attr conversion of '%s' failed (value='%s', ecert='%v')", | ||
attr.Name, attr.Value, attr.ECert) | ||
} | ||
case "AttrTrue": | ||
if attr.Value != "true" || attr.ECert != false { | ||
t.Fatalf("Attr conversion of '%s' failed (value='%s', ecert='%v')", | ||
attr.Name, attr.Value, attr.ECert) | ||
} | ||
case "AttrTrueWithECertAttr": | ||
if attr.Value != "true" || attr.ECert != true { | ||
t.Fatalf("Attr conversion of '%s' failed (value='%s', ecert='%v')", | ||
attr.Name, attr.Value, attr.ECert) | ||
} | ||
case "AttrFalse": | ||
if attr.Value != "false" || attr.ECert != false { | ||
t.Fatalf("Attr conversion of '%s' failed (value='%s', ecert='%v')", | ||
attr.Name, attr.Value, attr.ECert) | ||
} | ||
case "AttrStar": | ||
if attr.Value != "*" || attr.ECert != false { | ||
t.Fatalf("Attr conversion of '%s' failed (value='%s', ecert='%v')", | ||
attr.Name, attr.Value, attr.ECert) | ||
} | ||
case "AttrStarWithECertAttr": | ||
if attr.Value != "*" || attr.ECert != true { | ||
t.Fatalf("Attr conversion of '%s' failed (value='%s', ecert='%v')", | ||
attr.Name, attr.Value, attr.ECert) | ||
} | ||
default: | ||
t.Fatal("Unknown test case") | ||
} | ||
} | ||
|
||
err = processAttributes(negativeAttrs1, &clientCfg) | ||
if err == nil { | ||
t.Fatal("Negative test case 1 should have failed") | ||
} | ||
|
||
err = processAttributes(negativeAttrs2, &clientCfg) | ||
if err == nil { | ||
t.Fatal("Negative test case 2 should have failed") | ||
} | ||
} |
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
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