Skip to content

Commit

Permalink
test: ensure aal2 can not be used for password
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent 4d54fbb commit d9d39f0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion selfservice/strategy/password/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"testing"
"time"

"github.com/gofrs/uuid"

"github.com/ory/x/urlx"

kratos "github.com/ory/kratos-client-go"
Expand Down Expand Up @@ -40,7 +42,8 @@ func TestCompleteLogin(t *testing.T) {
conf, reg := internal.NewFastRegistryWithMocks(t)
conf.MustSet(config.ViperKeySelfServiceStrategyConfig+"."+string(identity.CredentialsTypePassword),
map[string]interface{}{"enabled": true})
publicTS, _ := testhelpers.NewKratosServer(t, reg)
router := x.NewRouterPublic()
publicTS, _ := testhelpers.NewKratosServerWithRouters(t, reg, router, x.NewRouterAdmin())

errTS := testhelpers.NewErrorTestServer(t, reg)
uiTS := testhelpers.NewLoginUIFlowEchoServer(t, reg)
Expand Down Expand Up @@ -117,6 +120,24 @@ func TestCompleteLogin(t *testing.T) {
})
})

t.Run("case=should fail because password can not handle AAL2", func(t *testing.T) {
f := testhelpers.InitializeLoginFlowViaAPI(t, apiClient, publicTS, false)

update, err := reg.LoginFlowPersister().GetLoginFlow(context.Background(), uuid.FromStringOrNil(f.Id))
require.NoError(t, err)
update.RequestedAAL = identity.AuthenticatorAssuranceLevel2
require.NoError(t, reg.LoginFlowPersister().UpdateLoginFlow(context.Background(), update))

req, err := http.NewRequest("POST", f.Ui.Action, bytes.NewBufferString(`{"method":"password"}`))
require.NoError(t, err)
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")

actual, res := testhelpers.MockMakeAuthenticatedRequest(t, reg, conf, router.Router, req)
assert.Contains(t, res.Request.URL.String(), publicTS.URL+login.RouteSubmitFlow)
assert.Equal(t, text.NewErrorValidationLoginNoStrategyFound().Text, gjson.GetBytes(actual, "ui.messages.0.text").String())
})

t.Run("should return an error because the request does not exist", func(t *testing.T) {
var check = func(t *testing.T, actual string) {
assert.Equal(t, int64(http.StatusNotFound), gjson.Get(actual, "code").Int(), "%s", actual)
Expand Down

0 comments on commit d9d39f0

Please sign in to comment.