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:
110
identity/credentials_code_test.go
Normal file
110
identity/credentials_code_test.go
Normal file
@@ -0,0 +1,110 @@
|
||||
// Copyright © 2024 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package identity
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCredentialsCodeAddressUnmarshalJSON(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want CredentialsCodeAddress
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "valid email address",
|
||||
input: `{"channel": "email", "address": "user@example.com"}`,
|
||||
want: CredentialsCodeAddress{
|
||||
Channel: CodeChannelEmail,
|
||||
Address: "user@example.com",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid SMS address",
|
||||
input: `{"channel": "sms", "address": "+1234567890"}`,
|
||||
want: CredentialsCodeAddress{
|
||||
Channel: CodeChannelSMS,
|
||||
Address: "+1234567890",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "invalid address type",
|
||||
input: `{"channel": "invalid", "address": "user@example.com"}`,
|
||||
want: CredentialsCodeAddress{},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "missing channel field",
|
||||
input: `{"address": "user@example.com"}`,
|
||||
want: CredentialsCodeAddress{},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid JSON structure",
|
||||
input: `{"channel": "email", "address": "user@example.com"`,
|
||||
want: CredentialsCodeAddress{},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var got CredentialsCodeAddress
|
||||
err := json.Unmarshal([]byte(tt.input), &got)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewCodeAddressType(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want CodeChannel
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "valid email address type",
|
||||
input: "email",
|
||||
want: CodeChannelEmail,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid SMS address type",
|
||||
input: "sms",
|
||||
want: CodeChannelSMS,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "invalid address type",
|
||||
input: "invalid",
|
||||
want: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := NewCodeChannel(tt.input)
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user