mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-16 21:08:00 +00:00
d0c23546ec
# Which Problems Are Solved Slice initialized with a fixed length instead of capacity, this leads to unexpected results when calling the append function. # How the Problems Are Solved fixed slice initialization, slice is initialized with zero length and with capacity of function's argument # Additional Changes test case added # Additional Context none Co-authored-by: Kolokhanin Roman <zuzmic@gmail.com> Co-authored-by: Tim Möhlmann <tim+github@zitadel.com>
130 lines
2.4 KiB
Go
130 lines
2.4 KiB
Go
package oidc
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/zitadel/oidc/v3/pkg/oidc"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
)
|
|
|
|
func TestResponseModeToBusiness(t *testing.T) {
|
|
type args struct {
|
|
responseMode oidc.ResponseMode
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want domain.OIDCResponseMode
|
|
}{
|
|
{
|
|
name: "empty",
|
|
args: args{""},
|
|
want: domain.OIDCResponseModeUnspecified,
|
|
},
|
|
{
|
|
name: "invalid",
|
|
args: args{"foo"},
|
|
want: domain.OIDCResponseModeUnspecified,
|
|
},
|
|
{
|
|
name: "query",
|
|
args: args{oidc.ResponseModeQuery},
|
|
want: domain.OIDCResponseModeQuery,
|
|
},
|
|
{
|
|
name: "fragment",
|
|
args: args{oidc.ResponseModeFragment},
|
|
want: domain.OIDCResponseModeFragment,
|
|
},
|
|
{
|
|
name: "post_form",
|
|
args: args{oidc.ResponseModeFormPost},
|
|
want: domain.OIDCResponseModeFormPost,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := ResponseModeToBusiness(tt.args.responseMode)
|
|
assert.Equal(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestResponseModeToOIDC(t *testing.T) {
|
|
type args struct {
|
|
responseMode domain.OIDCResponseMode
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want oidc.ResponseMode
|
|
}{
|
|
{
|
|
name: "unspecified",
|
|
args: args{domain.OIDCResponseModeUnspecified},
|
|
want: "",
|
|
},
|
|
{
|
|
name: "invalid",
|
|
args: args{99},
|
|
want: "",
|
|
},
|
|
{
|
|
name: "query",
|
|
args: args{domain.OIDCResponseModeQuery},
|
|
want: oidc.ResponseModeQuery,
|
|
},
|
|
{
|
|
name: "fragment",
|
|
args: args{domain.OIDCResponseModeFragment},
|
|
want: oidc.ResponseModeFragment,
|
|
},
|
|
{
|
|
name: "form_post",
|
|
args: args{domain.OIDCResponseModeFormPost},
|
|
want: oidc.ResponseModeFormPost,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := ResponseModeToOIDC(tt.args.responseMode)
|
|
assert.Equal(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPromptToBusiness(t *testing.T) {
|
|
type args struct {
|
|
oidcPrompt []string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want []domain.Prompt
|
|
}{
|
|
{
|
|
name: "unspecified",
|
|
args: args{nil},
|
|
want: []domain.Prompt{},
|
|
},
|
|
{
|
|
name: "invalid",
|
|
args: args{[]string{"non_existing_prompt"}},
|
|
want: []domain.Prompt{},
|
|
},
|
|
{
|
|
name: "prompt_none",
|
|
args: args{[]string{oidc.PromptNone}},
|
|
want: []domain.Prompt{domain.PromptNone},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := PromptToBusiness(tt.args.oidcPrompt)
|
|
assert.Equal(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|