Skip to content

Commit

Permalink
Tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshayman committed Feb 21, 2024
1 parent fea6651 commit a5f360f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 6 additions & 3 deletions verify/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func TestGetUserIdFromBody(t *testing.T) {
type testVerifyData struct {
name string
path string
salt string
chaincode string
mockStatusCode int
mockResBody string
Expand All @@ -174,15 +175,17 @@ func TestVerify(t *testing.T) {
{
name: "VERIFIED",
path: "/profile-one",
salt: "testSalt",
chaincode: "testchaincode",
mockStatusCode: http.StatusOK,
mockResBody: `{"hash": "$2a$12$ScGc2Q0t0rqqSJK1E2W/WuaRVAchaVWdUqb1hQi21cFTnOVvlIdry"}`,
mockResBody: `{"hash": "cadf727ffff23ec46c17d808a4884ea7566765182d1a2ffa88e4719bc1f7f9fb328e2abacc13202f2dc55b9d653919b79ecf02dd752de80285bbec57a57713d9"}`,
expectedStatus: "VERIFIED",
expectedErr: nil,
},
{
name: "BLOCKED",
path: "/profile-two",
salt: "testSalt",
chaincode: "invalid",
mockStatusCode: http.StatusForbidden,
mockResBody: `{"hash": "abcdefghijklmnopqrstuvwxyz"}`,
Expand All @@ -194,7 +197,7 @@ func TestVerify(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/profile-one" {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"hash": "$2a$12$ScGc2Q0t0rqqSJK1E2W/WuaRVAchaVWdUqb1hQi21cFTnOVvlIdry"}`))
w.Write([]byte(`{"hash": "cadf727ffff23ec46c17d808a4884ea7566765182d1a2ffa88e4719bc1f7f9fb328e2abacc13202f2dc55b9d653919b79ecf02dd752de80285bbec57a57713d9"}`))
}

if r.URL.Path == "/profile-two" {
Expand All @@ -206,7 +209,7 @@ func TestVerify(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {

status, err := verify(server.URL+testCase.path, testCase.chaincode)
status, err := verify(server.URL+testCase.path, testCase.chaincode, testCase.salt)

assert.Equal(t, testCase.expectedStatus, status)
assert.Equal(t, testCase.expectedErr, err)
Expand Down
10 changes: 5 additions & 5 deletions verify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,11 @@ func randSalt(n int) string {
/*
Function to verify the user
*/
func verify(profileURL string, chaincode string) (string, error) {
func verify(profileURL string, chaincode string, salt string) (string, error) {
type res struct {
Hash string `json:"hash"`
}

rand.Seed(time.Now().UnixNano())
var salt string = randSalt(21)

postBody, _ := json.Marshal(map[string]string{
"salt": salt,
})
Expand Down Expand Up @@ -284,7 +281,10 @@ func (d *deps) handler(request events.APIGatewayProxyRequest) (events.APIGateway
}, nil
}

status, err := verify(profileURL, chaincode)
rand.Seed(time.Now().UnixNano())
var salt string = randSalt(21)

status, err := verify(profileURL, chaincode, salt)
if err != nil {
logVerification(d.client, d.ctx, status, profileURL, userId)
setProfileStatus(d.client, d.ctx, userId, status)
Expand Down

0 comments on commit a5f360f

Please sign in to comment.