-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/litmuschaos/litmus into e…
…nable-otel Signed-off-by: namkyu1999 <[email protected]>
- Loading branch information
Showing
114 changed files
with
17,360 additions
and
1,243 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -13,6 +13,8 @@ import ( | |
"strings" | ||
"testing" | ||
|
||
"github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/authConfig" | ||
|
||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
|
||
"github.com/gin-gonic/gin" | ||
|
@@ -408,9 +410,11 @@ func TestLoginUser(t *testing.T) { | |
Password: "hashedPassword", | ||
Email: "[email protected]", | ||
} | ||
service.On("GetConfig", "salt").Return(&authConfig.AuthConfig{}, nil) | ||
service.On("FindUserByUsername", "testUser").Return(userFromDB, nil) | ||
service.On("CheckPasswordHash", "hashedPassword", "testPassword").Return(nil) | ||
service.On("GetSignedJWT", userFromDB).Return("someJWTToken", nil) | ||
service.On("UpdateUserByQuery", mock.Anything, mock.Anything).Return(nil) | ||
service.On("GetSignedJWT", userFromDB, mock.Anything).Return("someJWTToken", nil) | ||
project := &entities.Project{ | ||
ID: "someProjectID", | ||
} | ||
|
@@ -486,7 +490,7 @@ func TestUpdatePassword(t *testing.T) { | |
givenStrictPassword: false, | ||
givenServiceResponse: nil, | ||
expectedCode: http.StatusOK, | ||
expectedOutput: `{"message":"password has been updated successfully"}`, | ||
expectedOutput: `{"message":"password has been updated successfully","projectID":"someProjectID"}`, | ||
}, | ||
{ | ||
name: "Invalid new password", | ||
|
@@ -507,8 +511,6 @@ func TestUpdatePassword(t *testing.T) { | |
c.Request.Header.Set("Content-Type", "application/json") | ||
c.Set("username", tt.givenUsername) | ||
|
||
utils.StrictPasswordPolicy = tt.givenStrictPassword | ||
|
||
userPassword := entities.UserPassword{ | ||
Username: tt.givenUsername, | ||
OldPassword: "oldPass@123", | ||
|
@@ -520,9 +522,19 @@ func TestUpdatePassword(t *testing.T) { | |
Email: "[email protected]", | ||
IsInitialLogin: false, | ||
} | ||
userFromDB := &entities.User{ | ||
ID: "testUserID", | ||
Username: "testUser", | ||
Password: "hashedPassword", | ||
Email: "[email protected]", | ||
} | ||
service.On("FindUserByUsername", "testUser").Return(userFromDB, nil) | ||
service.On("GetUser", "testUID").Return(user, nil) | ||
service.On("UpdatePassword", &userPassword, true).Return(tt.givenServiceResponse) | ||
|
||
project := &entities.Project{ | ||
ID: "someProjectID", | ||
} | ||
service.On("GetOwnerProjectIDs", mock.Anything, "testUserID").Return([]*entities.Project{project}, nil) | ||
rest.UpdatePassword(service)(c) | ||
|
||
assert.Equal(t, tt.expectedCode, w.Code) | ||
|
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,44 @@ | ||
package response | ||
|
||
import ( | ||
"encoding/base64" | ||
|
||
"github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/authConfig" | ||
"github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/services" | ||
"github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/utils" | ||
log "github.com/sirupsen/logrus" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
func AddSalt(service services.ApplicationService) error { | ||
// generate salt and add/update to user collection | ||
// pass the salt in the below func which will act as jwt secret | ||
getSalt, err := service.GetConfig("salt") | ||
if err != nil && err != mongo.ErrNoDocuments { | ||
log.Error(err) | ||
return err | ||
} | ||
if getSalt != nil { | ||
return nil | ||
} | ||
|
||
salt, err := utils.RandomString(6) | ||
if err != nil { | ||
log.Error(err) | ||
return err | ||
} | ||
encodedSalt := base64.StdEncoding.EncodeToString([]byte(salt)) | ||
|
||
config := authConfig.AuthConfig{ | ||
Key: "salt", | ||
Value: encodedSalt, | ||
} | ||
|
||
err = service.CreateConfig(config) | ||
if err != nil { | ||
log.Error(err) | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.