Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
83 lines
2.8 KiB
Go
83 lines
2.8 KiB
Go
// Copyright © 2023 Ory Corp
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package password_test
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/ory/kratos/identity"
|
|
"github.com/ory/kratos/pkg"
|
|
"github.com/ory/kratos/pkg/testhelpers"
|
|
"github.com/ory/x/configx"
|
|
)
|
|
|
|
func TestDisabledEndpoint(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
conf, reg := pkg.NewFastRegistryWithMocks(t,
|
|
configx.WithValues(testhelpers.MethodEnableConfig(identity.CredentialsTypePassword, false)),
|
|
configx.WithValues(testhelpers.DefaultIdentitySchemaConfig("file://stub/sort.schema.json")),
|
|
)
|
|
|
|
publicTS, _ := testhelpers.NewKratosServer(t, reg)
|
|
|
|
c := testhelpers.NewClientWithCookies(t)
|
|
t.Run("case=should not login when password method is disabled", func(t *testing.T) {
|
|
f := testhelpers.InitializeLoginFlowViaAPICtx(context.Background(), t, c, publicTS, false)
|
|
|
|
res, err := c.PostForm(f.Ui.Action, url.Values{"method": {"password"}, "password_identifier": []string{"identifier"}, "password": []string{"password"}})
|
|
require.NoError(t, err)
|
|
defer func() { _ = res.Body.Close() }()
|
|
assert.Equal(t, http.StatusNotFound, res.StatusCode)
|
|
|
|
b, err := io.ReadAll(res.Body)
|
|
require.NoError(t, err)
|
|
assert.Contains(t, string(b), "This endpoint was disabled by system administrator", "%s", b)
|
|
})
|
|
|
|
t.Run("case=should not registration when password method is disabled", func(t *testing.T) {
|
|
f := testhelpers.InitializeRegistrationFlowViaAPICtx(t.Context(), t, c, publicTS)
|
|
|
|
res, err := c.PostForm(f.Ui.Action, url.Values{"method": {"password"}, "password_identifier": []string{"identifier"}, "password": []string{"password"}})
|
|
require.NoError(t, err)
|
|
defer func() { _ = res.Body.Close() }()
|
|
assert.Equal(t, http.StatusNotFound, res.StatusCode)
|
|
|
|
b, err := io.ReadAll(res.Body)
|
|
require.NoError(t, err)
|
|
assert.Contains(t, string(b), "This endpoint was disabled by system administrator", "%s", b)
|
|
})
|
|
|
|
t.Run("case=should not settings when password method is disabled", func(t *testing.T) {
|
|
testhelpers.SetDefaultIdentitySchema(conf, "file://stub/login.schema.json")
|
|
c := testhelpers.NewHTTPClientWithArbitrarySessionCookie(context.Background(), t, reg)
|
|
|
|
t.Run("method=GET", func(t *testing.T) {
|
|
t.Skip("GET is currently not supported for this endpoint.")
|
|
})
|
|
|
|
t.Run("method=POST", func(t *testing.T) {
|
|
f := testhelpers.InitializeSettingsFlowViaAPI(t, c, publicTS)
|
|
res, err := c.PostForm(f.Ui.Action, url.Values{
|
|
"method": {"password"},
|
|
"password": {"bar"},
|
|
})
|
|
require.NoError(t, err)
|
|
defer func() { _ = res.Body.Close() }()
|
|
assert.Equal(t, http.StatusNotFound, res.StatusCode)
|
|
|
|
b, err := io.ReadAll(res.Body)
|
|
require.NoError(t, err)
|
|
assert.Contains(t, string(b), "This endpoint was disabled by system administrator", "%s", b)
|
|
})
|
|
})
|
|
}
|