From 626216098fcd9411c1b4b7cb3b42784146b29924 Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Mon, 21 Mar 2022 19:02:25 +0100 Subject: [PATCH] fix: unstable webauthn order --- selfservice/flow/login/sort.go | 1 + ...oad_is_set_when_identity_has_webauthn.json | 6 ++--- ...swordless-case=webauthn_button_exists.json | 26 +++++++++---------- selfservice/strategy/webauthn/login_test.go | 4 +-- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/selfservice/flow/login/sort.go b/selfservice/flow/login/sort.go index 5724da3a683..c98a5834ec7 100644 --- a/selfservice/flow/login/sort.go +++ b/selfservice/flow/login/sort.go @@ -17,6 +17,7 @@ func sortNodes(ctx context.Context, n node.Nodes) error { node.LookupGroup, }), node.SortUseOrder([]string{ + "csrf_token", "identifier", "password", }), diff --git a/selfservice/strategy/webauthn/.snapshots/TestCompleteLogin-flow=mfa-case=webauthn_payload_is_set_when_identity_has_webauthn.json b/selfservice/strategy/webauthn/.snapshots/TestCompleteLogin-flow=mfa-case=webauthn_payload_is_set_when_identity_has_webauthn.json index 97bce7903c5..530c0805e50 100644 --- a/selfservice/strategy/webauthn/.snapshots/TestCompleteLogin-flow=mfa-case=webauthn_payload_is_set_when_identity_has_webauthn.json +++ b/selfservice/strategy/webauthn/.snapshots/TestCompleteLogin-flow=mfa-case=webauthn_payload_is_set_when_identity_has_webauthn.json @@ -2,8 +2,9 @@ { "attributes": { "disabled": false, - "name": "identifier", + "name": "csrf_token", "node_type": "input", + "required": true, "type": "hidden" }, "group": "default", @@ -14,9 +15,8 @@ { "attributes": { "disabled": false, - "name": "csrf_token", + "name": "identifier", "node_type": "input", - "required": true, "type": "hidden" }, "group": "default", diff --git a/selfservice/strategy/webauthn/.snapshots/TestCompleteLogin-flow=passwordless-case=webauthn_button_exists.json b/selfservice/strategy/webauthn/.snapshots/TestCompleteLogin-flow=passwordless-case=webauthn_button_exists.json index c9103c4c462..2b73efff9f5 100644 --- a/selfservice/strategy/webauthn/.snapshots/TestCompleteLogin-flow=passwordless-case=webauthn_button_exists.json +++ b/selfservice/strategy/webauthn/.snapshots/TestCompleteLogin-flow=passwordless-case=webauthn_button_exists.json @@ -2,34 +2,34 @@ { "attributes": { "disabled": false, - "name": "identifier", + "name": "csrf_token", "node_type": "input", "required": true, - "type": "text", - "value": "" + "type": "hidden" }, "group": "default", "messages": [], - "meta": { - "label": { - "id": 1070004, - "text": "ID", - "type": "info" - } - }, + "meta": {}, "type": "input" }, { "attributes": { "disabled": false, - "name": "csrf_token", + "name": "identifier", "node_type": "input", "required": true, - "type": "hidden" + "type": "text", + "value": "" }, "group": "default", "messages": [], - "meta": {}, + "meta": { + "label": { + "id": 1070004, + "text": "ID", + "type": "info" + } + }, "type": "input" }, { diff --git a/selfservice/strategy/webauthn/login_test.go b/selfservice/strategy/webauthn/login_test.go index 38369c31347..1ebd1159458 100644 --- a/selfservice/strategy/webauthn/login_test.go +++ b/selfservice/strategy/webauthn/login_test.go @@ -286,7 +286,7 @@ func TestCompleteLogin(t *testing.T) { t.Run("case=webauthn button exists", func(t *testing.T) { client := testhelpers.NewClientWithCookies(t) f := testhelpers.InitializeLoginFlowViaBrowser(t, client, publicTS, false, true) - testhelpers.SnapshotTExcept(t, f.Ui.Nodes, []string{"1.attributes.value"}) + testhelpers.SnapshotTExcept(t, f.Ui.Nodes, []string{"0.attributes.value"}) }) t.Run("case=webauthn shows error if user tries to sign in but no such user exists", func(t *testing.T) { @@ -459,7 +459,7 @@ func TestCompleteLogin(t *testing.T) { apiClient := testhelpers.NewHTTPClientWithIdentitySessionToken(t, reg, id) f := testhelpers.InitializeLoginFlowViaBrowser(t, apiClient, publicTS, false, true, testhelpers.InitFlowWithAAL(identity.AuthenticatorAssuranceLevel2)) - assert.Equal(t, gjson.GetBytes(id.Traits, "subject").String(), f.Ui.Nodes[0].Attributes.UiNodeInputAttributes.Value, jsonx.TestMarshalJSONString(t, f.Ui)) + assert.Equal(t, gjson.GetBytes(id.Traits, "subject").String(), f.Ui.Nodes[1].Attributes.UiNodeInputAttributes.Value, jsonx.TestMarshalJSONString(t, f.Ui)) testhelpers.SnapshotTExcept(t, f.Ui.Nodes, []string{ "0.attributes.value", "1.attributes.value",