Skip to content

Commit

Permalink
test: add settings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent 58b388c commit 6959565
Show file tree
Hide file tree
Showing 6 changed files with 676 additions and 1 deletion.
33 changes: 33 additions & 0 deletions selfservice/strategy/lookup/fixtures/settings/lookup_hidden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"attributes": {
"disabled": false,
"name": "csrf_token",
"required": true,
"type": "hidden",
"value": "dHlmZ251enczMWl6YnR5Y2syN2l3YXJmYmZ3NWI5ZDU="
},
"group": "default",
"messages": [],
"meta": {},
"type": "input"
},
{
"attributes": {
"disabled": false,
"name": "lookup_secret_reveal",
"type": "submit",
"value": "true"
},
"group": "lookup_secret",
"messages": [],
"meta": {
"label": {
"id": 1050007,
"text": "Reveal backup recovery codes",
"type": "info"
}
},
"type": "input"
}
]
33 changes: 33 additions & 0 deletions selfservice/strategy/lookup/fixtures/settings/lookup_setup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"attributes": {
"disabled": false,
"name": "csrf_token",
"required": true,
"type": "hidden",
"value": "dDVzdjQ5bWI3bWZrYnhta2dlczBmeDU4NHFzYWt2cW4="
},
"group": "default",
"messages": [],
"meta": {},
"type": "input"
},
{
"attributes": {
"disabled": false,
"name": "lookup_secret_regenerate",
"type": "submit",
"value": "true"
},
"group": "lookup_secret",
"messages": [],
"meta": {
"label": {
"id": 1050008,
"text": "Generate new backup recovery codes",
"type": "info"
}
},
"type": "input"
}
]
153 changes: 153 additions & 0 deletions selfservice/strategy/lookup/fixtures/settings/lookup_shown.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
[
{
"type": "input",
"group": "default",
"attributes": {
"name": "csrf_token",
"type": "hidden",
"value": "ZGY4cThmajNwNzJzMGVzN3ozbHBubHB5MWJrZDRzZmo=",
"required": true,
"disabled": false
},
"messages": [],
"meta": {}
},
{
"type": "text",
"group": "lookup_secret",
"attributes": {
"text": {
"id": 1050015,
"text": "key-0, used, key-2, key-3, used, key-5, key-6, used, key-8, key-9, used, key-11",
"type": "info",
"context": {
"secrets": [
{
"id": 1050009,
"text": "key-0",
"type": "info",
"context": {
"secret": "key-0"
}
},
{
"id": 1050014,
"text": "Secret was used at 2021-08-17 13:32:39 +0200 CEST",
"type": "info",
"context": {
"used_at": "2021-08-17T13:32:39+02:00"
}
},
{
"id": 1050009,
"text": "key-2",
"type": "info",
"context": {
"secret": "key-2"
}
},
{
"id": 1050009,
"text": "key-3",
"type": "info",
"context": {
"secret": "key-3"
}
},
{
"id": 1050014,
"text": "Secret was used at 2021-08-17 13:32:42 +0200 CEST",
"type": "info",
"context": {
"used_at": "2021-08-17T13:32:42+02:00"
}
},
{
"id": 1050009,
"text": "key-5",
"type": "info",
"context": {
"secret": "key-5"
}
},
{
"id": 1050009,
"text": "key-6",
"type": "info",
"context": {
"secret": "key-6"
}
},
{
"id": 1050014,
"text": "Secret was used at 2021-08-17 13:32:45 +0200 CEST",
"type": "info",
"context": {
"used_at": "2021-08-17T13:32:45+02:00"
}
},
{
"id": 1050009,
"text": "key-8",
"type": "info",
"context": {
"secret": "key-8"
}
},
{
"id": 1050009,
"text": "key-9",
"type": "info",
"context": {
"secret": "key-9"
}
},
{
"id": 1050014,
"text": "Secret was used at 2021-08-17 13:32:48 +0200 CEST",
"type": "info",
"context": {
"used_at": "2021-08-17T13:32:48+02:00"
}
},
{
"id": 1050009,
"text": "key-11",
"type": "info",
"context": {
"secret": "key-11"
}
}
]
}
},
"id": "lookup_secret_codes"
},
"messages": [],
"meta": {
"label": {
"id": 1050010,
"text": "These are your back up recovery codes. Please keep them in a safe place!",
"type": "info"
}
}
},
{
"type": "input",
"group": "lookup_secret",
"attributes": {
"name": "lookup_secret_regenerate",
"type": "submit",
"value": "true",
"disabled": false
},
"messages": [],
"meta": {
"label": {
"id": 1050008,
"text": "Generate new backup recovery codes",
"type": "info"
}
}
}
]
2 changes: 1 addition & 1 deletion selfservice/strategy/lookup/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (s *Strategy) continueSettingsFlowRegenerate(w http.ResponseWriter, r *http
func (s *Strategy) continueSettingsFlowConfirm(w http.ResponseWriter, r *http.Request, ctxUpdate *settings.UpdateContext, p *submitSelfServiceSettingsFlowWithLookupMethodBody) error {
codes := gjson.GetBytes(ctxUpdate.Flow.InternalContext, flow.PrefixInternalContextKey(s.ID(), internalContextKeyRegenerated)).Array()
if len(codes) != numCodes {
return errors.WithStack(herodot.ErrInternalServerError.WithReasonf("Expected to find lookup secrets in the internal context but found none."))
return errors.WithStack(herodot.ErrBadRequest.WithReasonf("You must (re-)generate recovery backup codes before you can save them."))
}

rc := make([]RecoveryCode, len(codes))
Expand Down

0 comments on commit 6959565

Please sign in to comment.