From a5f360ff41c891c347953b4edd5925097aef54a7 Mon Sep 17 00:00:00 2001 From: Lakshay Manchanda Date: Wed, 21 Feb 2024 22:04:41 +0530 Subject: [PATCH] Tests fixed --- verify/helpers_test.go | 9 ++++++--- verify/main.go | 10 +++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/verify/helpers_test.go b/verify/helpers_test.go index f5313f3..5f0a298 100644 --- a/verify/helpers_test.go +++ b/verify/helpers_test.go @@ -162,6 +162,7 @@ func TestGetUserIdFromBody(t *testing.T) { type testVerifyData struct { name string path string + salt string chaincode string mockStatusCode int mockResBody string @@ -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"}`, @@ -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" { @@ -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) diff --git a/verify/main.go b/verify/main.go index 05cb676..d5ce558 100644 --- a/verify/main.go +++ b/verify/main.go @@ -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, }) @@ -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)