mirror of
https://github.com/zitadel/zitadel.git
synced 2025-11-16 15:14:59 +00:00
# Which Problems Are Solved
- Adds support for the list users SCIM v2 endpoint
# How the Problems Are Solved
- Adds support for the list users SCIM v2 endpoints under `GET
/scim/v2/{orgID}/Users` and `POST /scim/v2/{orgID}/Users/.search`
# Additional Changes
- adds a new function `SearchUserMetadataForUsers` to the query layer to
query a metadata keyset for given user ids
- adds a new function `NewUserMetadataExistsQuery` to the query layer to
query a given metadata key value pair exists
- adds a new function `CountUsers` to the query layer to count users
without reading any rows
- handle `ErrorAlreadyExists` as scim errors `uniqueness`
- adds `NumberLessOrEqual` and `NumberGreaterOrEqual` query comparison
methods
- adds `BytesQuery` with `BytesEquals` and `BytesNotEquals` query
comparison methods
# Additional Context
Part of #8140
Supported fields for scim filters:
* `meta.created`
* `meta.lastModified`
* `id`
* `username`
* `name.familyName`
* `name.givenName`
* `emails` and `emails.value`
* `active` only eq and ne
* `externalId` only eq and ne
82 lines
1.8 KiB
Go
82 lines
1.8 KiB
Go
package http
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
gschema "github.com/gorilla/schema"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type SampleSchema struct {
|
|
Value *SampleSchemaValue `schema:"value"`
|
|
IntValue int `schema:"intvalue"`
|
|
}
|
|
|
|
type SampleSchemaValue struct{}
|
|
|
|
func (s *SampleSchemaValue) UnmarshalText(text []byte) error {
|
|
if string(text) == "foo" {
|
|
return nil
|
|
}
|
|
|
|
return errors.New("this is a test error")
|
|
}
|
|
|
|
func TestParser_UnwrapParserError(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
name string
|
|
query string
|
|
wantErr bool
|
|
assertUnwrappedError func(err error, unwrappedErr error)
|
|
}{
|
|
{
|
|
name: "unwrap ok",
|
|
query: "value=test",
|
|
wantErr: true,
|
|
assertUnwrappedError: func(_, err error) {
|
|
require.Equal(t, "this is a test error", err.Error())
|
|
},
|
|
},
|
|
{
|
|
name: "multiple errors",
|
|
query: "value=test&intvalue=foo",
|
|
wantErr: true,
|
|
assertUnwrappedError: func(err error, unwrappedErr error) {
|
|
require.Equal(t, err, unwrappedErr)
|
|
},
|
|
},
|
|
{
|
|
name: "no error",
|
|
query: "value=foo&intvalue=1",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
p := NewParser()
|
|
encodedFormData := url.Values{}.Encode()
|
|
r, err := http.NewRequest(http.MethodPost, "http://exmaple.com?"+tt.query, bytes.NewBufferString(encodedFormData))
|
|
require.NoError(t, err)
|
|
|
|
data := new(SampleSchema)
|
|
err = p.Parse(r, data)
|
|
if !tt.wantErr {
|
|
require.NoError(t, err)
|
|
require.Nil(t, p.UnwrapParserError(err))
|
|
return
|
|
}
|
|
|
|
require.Error(t, err)
|
|
require.IsType(t, gschema.MultiError{}, err)
|
|
|
|
unwrappedErr := p.UnwrapParserError(err)
|
|
require.Error(t, unwrappedErr)
|
|
tt.assertUnwrappedError(err, unwrappedErr)
|
|
})
|
|
}
|
|
}
|