From cd74c8a1a102a94434747e770f3df0cdb1ccb77f Mon Sep 17 00:00:00 2001 From: Keith Smith Date: Wed, 15 Nov 2017 16:46:06 -0500 Subject: [PATCH] [FAB-6991] Fix max enrollments for bootstrap user The max enrollments for the bootstrap user should use the max enrollments setting of the server. This is needed in order to allow starting the server to enforce one-time passwords and also use the default bootstrap user settings. The additional test case failed prior to this change set, but now succeeds. Change-Id: Ibbad7c9e0efd4679138c41277b1f69ebe360132d Signed-off-by: Keith Smith --- cmd/fabric-ca-server/config.go | 1 - cmd/fabric-ca-server/main_test.go | 11 +++++++++++ lib/server.go | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/fabric-ca-server/config.go b/cmd/fabric-ca-server/config.go index a42a7c36c..6dee99363 100644 --- a/cmd/fabric-ca-server/config.go +++ b/cmd/fabric-ca-server/config.go @@ -165,7 +165,6 @@ registry: pass: <<>> type: client affiliation: "" - maxenrollments: -1 attrs: hf.Registrar.Roles: "client,user,peer,validator,auditor" hf.Registrar.DelegateRoles: "client,user,validator,auditor" diff --git a/cmd/fabric-ca-server/main_test.go b/cmd/fabric-ca-server/main_test.go index e915662b6..4a94f27d3 100644 --- a/cmd/fabric-ca-server/main_test.go +++ b/cmd/fabric-ca-server/main_test.go @@ -121,6 +121,17 @@ func TestErrors(t *testing.T) { } } +func TestOneTimePass(t *testing.T) { + testDir := "oneTimePass" + os.RemoveAll(testDir) + defer os.RemoveAll(testDir) + // Test with "-b" option + err := RunMain([]string{cmdName, "init", "-b", "admin:adminpw", "--registry.maxenrollments", "1", "-H", testDir}) + if err != nil { + t.Fatalf("Failed to init server with one time passwords: %s", err) + } +} + func TestLDAP(t *testing.T) { os.RemoveAll(ldapTestDir) defer os.RemoveAll(ldapTestDir) diff --git a/lib/server.go b/lib/server.go index a30ada857..c149a742b 100644 --- a/lib/server.go +++ b/lib/server.go @@ -204,7 +204,7 @@ func (s *Server) RegisterBootstrapUser(user, pass, affiliation string) error { Pass: pass, Type: "user", Affiliation: affiliation, - MaxEnrollments: s.CA.Config.Registry.MaxEnrollments, + MaxEnrollments: 0, // 0 means to use the server's max enrollment setting Attrs: map[string]string{ attrRoles: allRoles, attrDelegateRoles: allRoles,