Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ivixvi/scim-patch
go 1.22

require (
github.com/elimity-com/scim v0.0.0-20240320110924-172bf2aee9c8
github.com/elimity-com/scim v0.0.0-20260328082225-d5e7ba418946
github.com/scim2/filter-parser/v2 v2.2.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ github.com/di-wu/xsd-datetime v1.0.0 h1:vZoGNkbzpBNoc+JyfVLEbutNDNydYV8XwHeV7eUJ
github.com/di-wu/xsd-datetime v1.0.0/go.mod h1:i3iEhrP3WchwseOBeIdW/zxeoleXTOzx1WyDXgdmOww=
github.com/elimity-com/scim v0.0.0-20240320110924-172bf2aee9c8 h1:0+BTyxIYgiVAry/P5s8R4dYuLkhB9Nhso8ogFWNr4IQ=
github.com/elimity-com/scim v0.0.0-20240320110924-172bf2aee9c8/go.mod h1:JkjcmqbLW+khwt2fmBPJFBhx2zGZ8XobRZ+O0VhlwWo=
github.com/elimity-com/scim v0.0.0-20260328082225-d5e7ba418946 h1:2UDLPwppIwWSH2MIlsIUnX21LdlVRbQt6PKdZ/chx58=
github.com/elimity-com/scim v0.0.0-20260328082225-d5e7ba418946/go.mod h1:JkjcmqbLW+khwt2fmBPJFBhx2zGZ8XobRZ+O0VhlwWo=
github.com/scim2/filter-parser/v2 v2.2.0 h1:QGadEcsmypxg8gYChRSM2j1edLyE/2j72j+hdmI4BJM=
github.com/scim2/filter-parser/v2 v2.2.0/go.mod h1:jWnkDToqX/Y0ugz0P5VvpVEUKcWcyHHj+X+je9ce5JA=
18 changes: 8 additions & 10 deletions path_not_specified_add_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package scimpatch_test

import (
"context"
"fmt"
"testing"

"github.com/elimity-com/scim"
"github.com/elimity-com/scim/schema"
scimpatch "github.com/ivixvi/scim-patch"
)

// TestPathNotSpecifiedAdd は Patcher.Apply の path指定をしていない add 操作の正常系をテストします
Expand Down Expand Up @@ -514,18 +512,18 @@ func TestPathNotSpecifiedAdd(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Log(tc.name)
// Create a Patcher instance with a dummy schema
patcher := scimpatch.NewPatcher(schema.CoreUserSchema(), []schema.Schema{

// Apply the PatchOperation using PR's ApplyPatch
result, err := scim.ApplyPatch(tc.data, []scim.PatchOperation{tc.op},
schema.CoreUserSchema(),
schema.ExtensionEnterpriseUser(),
TestExtensionSchema,
}, nil)

// Apply the PatchOperation
result, changed, err := patcher.Apply(context.TODO(), tc.op, tc.data)
)
if err != nil {
t.Fatalf("Apply() returned an unexpected error: %v", err)
t.Fatalf("ApplyPatch() returned an unexpected error: %v", err)
}
// Check if the result matches the expected data
// Check changed by comparing data vs result
changed := fmt.Sprint(result) != fmt.Sprint(tc.data)
if changed != tc.expectedChanged {
t.Errorf("changed:\n actual : %v\n expected: %v", changed, tc.expectedChanged)
}
Expand Down
22 changes: 9 additions & 13 deletions path_not_specified_replace_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package scimpatch_test

import (
"context"
"fmt"
"testing"

"github.com/elimity-com/scim"
"github.com/elimity-com/scim/schema"
scimpatch "github.com/ivixvi/scim-patch"
)

// TestPathNotSpecifiedReplace は Patcher.Apply の path指定をしていない replace 操作の正常系をテストします
Expand Down Expand Up @@ -429,20 +427,18 @@ func TestPathNotSpecifiedReplace(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Log(tc.name)
// Create a Patcher instance with a dummy schema
patcher := scimpatch.NewPatcher(
schema.CoreUserSchema(),
[]schema.Schema{
schema.ExtensionEnterpriseUser(),
TestExtensionSchema,
}, nil)

// Apply the PatchOperation
result, changed, err := patcher.Apply(context.TODO(), tc.op, tc.data)
// Apply the PatchOperation using PR's ApplyPatch
result, err := scim.ApplyPatch(tc.data, []scim.PatchOperation{tc.op},
schema.CoreUserSchema(),
schema.ExtensionEnterpriseUser(),
TestExtensionSchema,
)
if err != nil {
t.Fatalf("Apply() returned an unexpected error: %v", err)
t.Fatalf("ApplyPatch() returned an unexpected error: %v", err)
}
// Check if the result matches the expected data
// Check changed by comparing data vs result
changed := fmt.Sprint(result) != fmt.Sprint(tc.data)
if changed != tc.expectedChanged {
t.Errorf("changed:\n actual : %v\n expected: %v", changed, tc.expectedChanged)
}
Expand Down
22 changes: 9 additions & 13 deletions path_specified_add_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package scimpatch_test

import (
"context"
"fmt"
"testing"

"github.com/elimity-com/scim"
"github.com/elimity-com/scim/schema"
scimpatch "github.com/ivixvi/scim-patch"
)

// TestPathSpecifiedAdd は Patcher.Apply の path指定をしているadd操作の正常系をテストします
Expand Down Expand Up @@ -609,20 +607,18 @@ func TestPathSpecifiedAdd(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Log(tc.name)
// Create a Patcher instance with a dummy schema
patcher := scimpatch.NewPatcher(
schema.CoreUserSchema(),
[]schema.Schema{
schema.ExtensionEnterpriseUser(),
TestExtensionSchema,
}, nil)

// Apply the PatchOperation
result, changed, err := patcher.Apply(context.TODO(), tc.op, tc.data)
// Apply the PatchOperation using PR's ApplyPatch
result, err := scim.ApplyPatch(tc.data, []scim.PatchOperation{tc.op},
schema.CoreUserSchema(),
schema.ExtensionEnterpriseUser(),
TestExtensionSchema,
)
if err != nil {
t.Fatalf("Apply() returned an unexpected error: %v", err)
t.Fatalf("ApplyPatch() returned an unexpected error: %v", err)
}
// Check if the result matches the expected data
// Check changed by comparing data vs result
changed := fmt.Sprint(result) != fmt.Sprint(tc.data)
if changed != tc.expectedChanged {
t.Errorf("changed:\n actual : %v\n expected: %v", changed, tc.expectedChanged)
}
Expand Down
36 changes: 16 additions & 20 deletions path_specified_remove_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package scimpatch_test

import (
"context"
"fmt"
"testing"

"github.com/elimity-com/scim"
"github.com/elimity-com/scim/errors"
"github.com/elimity-com/scim/schema"
scimpatch "github.com/ivixvi/scim-patch"
)

// TestPatcher_Apply は Patcher.Apply の Remove の正常系をテストします
Expand Down Expand Up @@ -435,20 +433,18 @@ func TestPathSpecifiedRemove(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Log(tc.name)
// Create a Patcher instance with a dummy schema
patcher := scimpatch.NewPatcher(
schema.CoreUserSchema(),
[]schema.Schema{
schema.ExtensionEnterpriseUser(),
TestExtensionSchema,
}, nil)

// Apply the PatchOperation
result, changed, err := patcher.Apply(context.TODO(), tc.op, tc.data)
// Apply the PatchOperation using PR's ApplyPatch
result, err := scim.ApplyPatch(tc.data, []scim.PatchOperation{tc.op},
schema.CoreUserSchema(),
schema.ExtensionEnterpriseUser(),
TestExtensionSchema,
)
if err != nil {
t.Fatalf("Apply() returned an unexpected error: %v", err)
t.Fatalf("ApplyPatch() returned an unexpected error: %v", err)
}
// Check if the result matches the expected data
// Check changed by comparing data vs result
changed := fmt.Sprint(result) != fmt.Sprint(tc.data)
if changed != tc.expectedChanged {
t.Errorf("changed:\n actual : %v\n expected: %v", changed, tc.expectedChanged)
}
Expand Down Expand Up @@ -480,24 +476,24 @@ func TestRemoveError(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Log(tc.name)
// Create a Patcher instance with a dummy schema
patcher := scimpatch.Patcher{}

// Apply the PatchOperation
_, _, err := patcher.Apply(context.TODO(), tc.op, map[string]interface{}{})
// Apply the PatchOperation using PR's ApplyPatch
_, err := scim.ApplyPatch(map[string]interface{}{}, []scim.PatchOperation{tc.op},
schema.CoreUserSchema(),
)
if err == nil {
t.Fatalf("Apply() not returned error")
t.Fatalf("ApplyPatch() not returned error")
}
scimError, ok := err.(errors.ScimError)
if !ok {
t.Fatalf("Apply() not returned ScimError: %v", err)
t.Fatalf("ApplyPatch() not returned ScimError: %v", err)
}

// Check if the result matches the expected data
if !(tc.expected.Detail == scimError.Detail &&
tc.expected.Status == scimError.Status &&
tc.expected.ScimType == scimError.ScimType) {
t.Fatalf("Apply() not returned Expected ScimError: %v", scimError)
t.Fatalf("ApplyPatch() not returned Expected ScimError: %v", scimError)
}
})
}
Expand Down
22 changes: 9 additions & 13 deletions path_specified_replace_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package scimpatch_test

import (
"context"
"fmt"
"testing"

"github.com/elimity-com/scim"
"github.com/elimity-com/scim/schema"
scimpatch "github.com/ivixvi/scim-patch"
)

// TestPathSpecifiedReplace は Patcher.Apply の path指定をしているreplace操作の正常系をテストします
Expand Down Expand Up @@ -488,20 +486,18 @@ func TestPathSpecifiedReplace(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Log(tc.name)
// Create a Patcher instance with a dummy schema
patcher := scimpatch.NewPatcher(
schema.CoreUserSchema(),
[]schema.Schema{
schema.ExtensionEnterpriseUser(),
TestExtensionSchema,
}, nil)

// Apply the PatchOperation
result, changed, err := patcher.Apply(context.TODO(), tc.op, tc.data)
// Apply the PatchOperation using PR's ApplyPatch
result, err := scim.ApplyPatch(tc.data, []scim.PatchOperation{tc.op},
userSchemaWithExternalId(),
schema.ExtensionEnterpriseUser(),
TestExtensionSchema,
)
if err != nil {
t.Fatalf("Apply() returned an unexpected error: %v", err)
t.Fatalf("ApplyPatch() returned an unexpected error: %v", err)
}
// Check if the result matches the expected data
// Check changed by comparing data vs result
changed := fmt.Sprint(result) != fmt.Sprint(tc.data)
if changed != tc.expectedChanged {
t.Errorf("changed:\n actual : %v\n expected: %v", changed, tc.expectedChanged)
}
Expand Down
13 changes: 13 additions & 0 deletions schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,16 @@ var TestExtensionSchema = schema.Schema{
})),
},
}

// userSchemaWithExternalId returns CoreUserSchema with externalId added,
// since ApplyPatch resolves attributes from the main schema and externalId
// is a common attribute (RFC 7643 Section 3.1) not included in CoreUserSchema.
func userSchemaWithExternalId() schema.Schema {
s := schema.CoreUserSchema()
s.Attributes = append(s.Attributes,
schema.SimpleCoreAttribute(schema.SimpleStringParams(schema.StringParams{
Name: "externalId",
})),
)
return s
}
Loading