snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
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
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
This commit is contained in:
78
cmd/identities/validate_test.go
Normal file
78
cmd/identities/validate_test.go
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package identities_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/ory/kratos/cmd/identities"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestValidateIdentity(t *testing.T) {
|
||||
var testCmd = func() (*cobra.Command, *bytes.Buffer, *bytes.Buffer) {
|
||||
out, err := &bytes.Buffer{}, &bytes.Buffer{}
|
||||
cmd := &cobra.Command{}
|
||||
cmd.SetOut(out)
|
||||
cmd.SetErr(err)
|
||||
return cmd, out, err
|
||||
}
|
||||
|
||||
var testSchemaGetter = func(resp map[string]interface{}) identities.SchemaGetter {
|
||||
return func(_ context.Context, _ string) (map[string]interface{}, *http.Response, error) {
|
||||
return resp, nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
for i, tc := range []struct {
|
||||
description string
|
||||
payload string
|
||||
expectedRequiredError string
|
||||
identitySchema map[string]interface{}
|
||||
}{
|
||||
{
|
||||
description: "requires schema_id from swagger schema",
|
||||
payload: "{}",
|
||||
expectedRequiredError: "schema_id",
|
||||
},
|
||||
{
|
||||
description: "requires traits from swagger schema",
|
||||
payload: `{"schema_id": "case2"}`,
|
||||
expectedRequiredError: "traits",
|
||||
},
|
||||
{
|
||||
description: "requires custom trait key",
|
||||
payload: `{"schema_id": "case3", "traits": {}}`,
|
||||
expectedRequiredError: "random-property",
|
||||
identitySchema: map[string]interface{}{
|
||||
"type": "object",
|
||||
"required": []string{"random-property"},
|
||||
"properties": map[string]interface{}{
|
||||
"random-property": map[string]interface{}{
|
||||
"type": "string",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(fmt.Sprintf("case=%d/description=%s", i, tc.description), func(t *testing.T) {
|
||||
cmd, stdOut, stdErr := testCmd()
|
||||
|
||||
if tc.identitySchema == nil {
|
||||
tc.identitySchema = map[string]interface{}{}
|
||||
}
|
||||
err := identities.ValidateIdentity(cmd, "test identity", tc.payload, testSchemaGetter(tc.identitySchema))
|
||||
assert.Error(t, err, stdOut.String(), stdErr.String())
|
||||
assert.Len(t, stdOut.String(), 0, stdErr.String())
|
||||
assert.Contains(t, stdErr.String(), "required", stdOut.String())
|
||||
assert.Contains(t, stdErr.String(), tc.expectedRequiredError, stdOut.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user