diff --git a/go.mod b/go.mod index 28b4268..d5e990b 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 2640683..27b5762 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/path_not_specified_add_test.go b/path_not_specified_add_test.go index 20161fa..b154f7a 100644 --- a/path_not_specified_add_test.go +++ b/path_not_specified_add_test.go @@ -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 操作の正常系をテストします @@ -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) } diff --git a/path_not_specified_replace_test.go b/path_not_specified_replace_test.go index 3bad503..cc02f9d 100644 --- a/path_not_specified_replace_test.go +++ b/path_not_specified_replace_test.go @@ -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 操作の正常系をテストします @@ -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) } diff --git a/path_specified_add_test.go b/path_specified_add_test.go index 6139011..8269845 100644 --- a/path_specified_add_test.go +++ b/path_specified_add_test.go @@ -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操作の正常系をテストします @@ -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) } diff --git a/path_specified_remove_test.go b/path_specified_remove_test.go index 733e3f5..a085546 100644 --- a/path_specified_remove_test.go +++ b/path_specified_remove_test.go @@ -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 の正常系をテストします @@ -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) } @@ -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) } }) } diff --git a/path_specified_replace_test.go b/path_specified_replace_test.go index 0bfde41..394419f 100644 --- a/path_specified_replace_test.go +++ b/path_specified_replace_test.go @@ -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操作の正常系をテストします @@ -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) } diff --git a/schema_test.go b/schema_test.go index 15a8ea3..7e8cbe0 100644 --- a/schema_test.go +++ b/schema_test.go @@ -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 +}