mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 20:57:31 +00:00
feat: list users scim v2 endpoint (#9187)
# 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
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/schema"
|
||||
@@ -26,3 +27,24 @@ func (p *Parser) Parse(r *http.Request, data interface{}) error {
|
||||
|
||||
return p.decoder.Decode(data, r.Form)
|
||||
}
|
||||
|
||||
func (p *Parser) UnwrapParserError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// try to unwrap the error
|
||||
var multiErr schema.MultiError
|
||||
if errors.As(err, &multiErr) && len(multiErr) == 1 {
|
||||
for _, v := range multiErr {
|
||||
var schemaErr schema.ConversionError
|
||||
if errors.As(v, &schemaErr) {
|
||||
return schemaErr.Err
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
81
internal/api/http/parser_test.go
Normal file
81
internal/api/http/parser_test.go
Normal file
@@ -0,0 +1,81 @@
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user