Skip to content

Commit

Permalink
Merge 91e8a7a into c69ee9e
Browse files Browse the repository at this point in the history
  • Loading branch information
bsoniam committed Jun 21, 2019
2 parents c69ee9e + 91e8a7a commit bdd83ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions pkg/management/component.go
Expand Up @@ -13,6 +13,10 @@ import (
kc "github.com/cloudtrust/keycloak-client"
)

const (
initPasswordAction = "sms-password-set"
)

// KeycloakClient are methods from keycloak-client used by this component
type KeycloakClient interface {
GetRealms(accessToken string) ([]kc.RealmRepresentation, error)
Expand Down Expand Up @@ -474,8 +478,8 @@ func (c *component) ResetPassword(ctx context.Context, realmName string, userID
}

//store the API call into the DB
// the error should be treated
_ = c.reportEvent(ctx, "INIT_PASSWORD", database.CtEventRealmName, realmName, database.CtEventUserID, userID)
//_ = c.reportEvent(ctx, "INIT_PASSWORD", database.CtEventRealmName, realmName, database.CtEventUserID, userID)
// removed as it is not used

return nil
}
Expand All @@ -493,6 +497,10 @@ func (c *component) ExecuteActionsEmail(ctx context.Context, realmName string, u

for _, requiredAction := range requiredActions {
actions = append(actions, string(requiredAction))
if string(requiredAction) == initPasswordAction {
//store the API call into the DB
_ = c.reportEvent(ctx, "INIT_PASSWORD", database.CtEventRealmName, realmName, database.CtEventUserID, userID)
}
}

return c.keycloakClient.ExecuteActionsEmail(accessToken, realmName, userID, actions, paramKV...)
Expand Down
6 changes: 4 additions & 2 deletions pkg/management/component_test.go
Expand Up @@ -1281,8 +1281,8 @@ func TestExecuteActionsEmail(t *testing.T) {
var accessToken = "TOKEN=="
var realmName = "master"
var userID = "1245-7854-8963"
var reqActions = []api.RequiredAction{"action1", "action2"}
var actions = []string{"action1", "action2"}
var reqActions = []api.RequiredAction{initPasswordAction, "action1", "action2"}
var actions = []string{initPasswordAction, "action1", "action2"}

var key1 = "key1"
var value1 = "value1"
Expand All @@ -1291,9 +1291,11 @@ func TestExecuteActionsEmail(t *testing.T) {

// Send email actions
{

mockKeycloakClient.EXPECT().ExecuteActionsEmail(accessToken, realmName, userID, actions, key1, value1, key2, value2).Return(nil).Times(1)

var ctx = context.WithValue(context.Background(), cs.CtContextAccessToken, accessToken)
mockEventDBModule.EXPECT().ReportEvent(ctx, "INIT_PASSWORD", "back-office", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(2)

err := managementComponent.ExecuteActionsEmail(ctx, "master", userID, reqActions, key1, value1, key2, value2)

Expand Down

0 comments on commit bdd83ff

Please sign in to comment.