Skip to content

Commit

Permalink
generateToken modified to accept username and name
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarmrr committed Jul 25, 2019
1 parent ad52f23 commit 9fa762c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions testapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ func (testApp *TestApp) CheckResponseCode(t *testing.T, expected, actual int) {

// GetToken gets a token to connect to API
func (testApp *TestApp) GetToken(tenantID string, userID string, scope []string) string {
return testApp.generateToken(tenantID, userID, uuid.UUID{}.String(), "", scope, false)
return testApp.generateToken(tenantID, userID, uuid.UUID{}.String(), "", "", "", scope, false)
}

// GetAdminToken returns a test token
func (testApp *TestApp) GetAdminToken(tenantID string, userID string, scope []string) string {
return testApp.generateToken(tenantID, userID, uuid.UUID{}.String(), "", scope, true)
return testApp.generateToken(tenantID, userID, uuid.UUID{}.String(), "", "", "", scope, true)
}

// GetTokenWithExternalID returns a test token with different external IDs for types such as Appliance, Session, User. These external IDs are used with REST api is invoked from another REST API service as opposed to the getting hit from UI by the user.
func (testApp *TestApp) GetTokenWithExternalID(tenantID string, userID string, externalID string, externalIDType string, scope []string) string {
return testApp.generateToken(tenantID, userID, externalID, externalIDType, scope, true)
// GetFullToken returns a test token with all the fields along with different external IDs for types such as Appliance, Session, User. These external IDs are used with REST api is invoked from another REST API service as opposed to the getting hit from UI by the user.
func (testApp *TestApp) GetFullToken(tenantID string, userID string, username string, name string, externalID string, externalIDType string, scope []string) string {
return testApp.generateToken(tenantID, userID, username, name, externalID, externalIDType, scope, true)
}

// generateToken generates and return token
func (testApp *TestApp) generateToken(tenantID string, userID string, externalID string, externalIDType string, scope []string, admin bool) string {
func (testApp *TestApp) generateToken(tenantID string, userID string, username string, name string, externalID string, externalIDType string, scope []string, admin bool) string {
hmacSampleSecret := []byte(testApp.application.Config.GetString("ISLA_JWT_SECRET"))

token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
Expand All @@ -98,7 +98,8 @@ func (testApp *TestApp) generateToken(tenantID string, userID string, externalID
"tenant": tenantID,
"user": userID,
"admin": admin,
"name": "username",
"email": username,
"displayName": name,
"scope": scope,
"externalId": externalID,
"externalIdType": externalIDType,
Expand Down

0 comments on commit 9fa762c

Please sign in to comment.