-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-6068] Update state after all checks done
User state will now be updated only after the user has successfully logged in and all the enrollment checks have been done and resulted in no errors. Change-Id: I5ab1730f869ba615d306c47599aad1cd622a905e Signed-off-by: Saad Karim <[email protected]>
- Loading branch information
Saad Karim
committed
Sep 18, 2017
1 parent
c41f4f1
commit 2dd4f5b
Showing
6 changed files
with
112 additions
and
10 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
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,80 @@ | ||
/* | ||
Copyright IBM Corp. 2017 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 lib | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric-ca/api" | ||
"github.com/hyperledger/fabric-ca/util" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestStateUpdate(t *testing.T) { | ||
os.RemoveAll(rootDir) | ||
os.RemoveAll("../testdata/msp") | ||
defer os.RemoveAll(rootDir) | ||
defer os.RemoveAll("../testdata/msp") | ||
|
||
var err error | ||
srv := TestGetRootServer(t) | ||
|
||
err = srv.Start() | ||
assert.NoError(t, err, "Failed to start server") | ||
|
||
client := getTestClient(rootPort) | ||
_, err = client.Enroll(&api.EnrollmentRequest{ | ||
Name: "admin", | ||
Secret: "adminpw", | ||
}) | ||
assert.NoError(t, err, "Failed to enroll 'admin' user") | ||
|
||
registry := srv.CA.DBAccessor() | ||
userInfo, err := registry.GetUserInfo("admin") | ||
assert.NoError(t, err, "Failed to get user 'admin' from database") | ||
// User state should have gotten updated to 1 after a successful enrollment | ||
if userInfo.State != 1 { | ||
t.Error("Incorrect state set for user") | ||
} | ||
|
||
// Send bad CSR to cause the enroll to fail but the login to succeed | ||
reqNet := &api.EnrollmentRequestNet{} | ||
reqNet.SignRequest.Request = "badcsr" | ||
body, err := util.Marshal(reqNet, "SignRequest") | ||
assert.NoError(t, err, "Failed to marshal enroll request") | ||
|
||
// Send the CSR to the fabric-ca server with basic auth header | ||
post, err := client.newPost("enroll", body) | ||
assert.NoError(t, err, "Failed to create post request") | ||
post.SetBasicAuth("admin", "adminpw") | ||
err = client.SendReq(post, nil) | ||
if assert.Error(t, err, "Should have failed due to bad csr") { | ||
assert.Contains(t, err.Error(), "CSR Decode failed") | ||
} | ||
|
||
// State should not have gotten updated because the enrollment failed | ||
userInfo, err = registry.GetUserInfo("admin") | ||
assert.NoError(t, err, "Failed to get user 'admin' from database") | ||
if userInfo.State != 1 { | ||
t.Error("Incorrect state set for user") | ||
} | ||
|
||
err = srv.Stop() | ||
assert.NoError(t, err, "Failed to stop server") | ||
|
||
} |
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