Skip to content

Commit

Permalink
CLOUDTRUST-1314 Add INIT_PASSWORD event
Browse files Browse the repository at this point in the history
  • Loading branch information
bsoniam authored and harture committed Jul 1, 2019
1 parent 735af35 commit 5e453f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion pkg/management/component.go
Original file line number Diff line number Diff line change
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 @@ -468,7 +472,6 @@ 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)

return nil
Expand All @@ -487,6 +490,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
Original file line number Diff line number Diff line change
Expand Up @@ -1283,8 +1283,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 @@ -1293,9 +1293,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 5e453f2

Please sign in to comment.