-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add console API fallback for identity schema data sources #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| ory "github.com/ory/client-go" | ||
| ) | ||
|
|
||
| func TestExtractSchemasFromProjectConfig(t *testing.T) { | ||
| t.Run("nil identity service", func(t *testing.T) { | ||
| project := &ory.Project{ | ||
| Services: ory.ProjectServices{}, | ||
| } | ||
| schemas, err := extractSchemasFromProjectConfig(project) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if len(schemas) != 0 { | ||
| t.Fatalf("expected 0 schemas, got %d", len(schemas)) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("base64 schema", func(t *testing.T) { | ||
| // {"type":"object","properties":{"traits":{"type":"object"}}} | ||
| b64 := "eyJ0eXBlIjoib2JqZWN0IiwicHJvcGVydGllcyI6eyJ0cmFpdHMiOnsidHlwZSI6Im9iamVjdCJ9fX0=" | ||
| project := &ory.Project{ | ||
| Services: ory.ProjectServices{ | ||
| Identity: &ory.ProjectServiceIdentity{ | ||
| Config: map[string]interface{}{ | ||
| "identity": map[string]interface{}{ | ||
| "schemas": []interface{}{ | ||
| map[string]interface{}{ | ||
| "id": "test-schema-hash", | ||
| "url": "base64://" + b64, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| schemas, err := extractSchemasFromProjectConfig(project) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if len(schemas) != 1 { | ||
| t.Fatalf("expected 1 schema, got %d", len(schemas)) | ||
| } | ||
| if schemas[0].GetId() != "test-schema-hash" { | ||
| t.Errorf("expected id 'test-schema-hash', got %q", schemas[0].GetId()) | ||
| } | ||
| if schemas[0].Schema == nil { | ||
| t.Fatal("expected schema content to be decoded, got nil") | ||
| } | ||
| if schemas[0].Schema["type"] != "object" { | ||
| t.Errorf("expected schema type 'object', got %v", schemas[0].Schema["type"]) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("preset schema returns empty object", func(t *testing.T) { | ||
| project := &ory.Project{ | ||
| Services: ory.ProjectServices{ | ||
| Identity: &ory.ProjectServiceIdentity{ | ||
| Config: map[string]interface{}{ | ||
| "identity": map[string]interface{}{ | ||
| "schemas": []interface{}{ | ||
| map[string]interface{}{ | ||
| "id": "preset://username", | ||
| "url": "preset://username", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| schemas, err := extractSchemasFromProjectConfig(project) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if len(schemas) != 1 { | ||
| t.Fatalf("expected 1 schema, got %d", len(schemas)) | ||
| } | ||
| if schemas[0].GetId() != "preset://username" { | ||
| t.Errorf("expected id 'preset://username', got %q", schemas[0].GetId()) | ||
| } | ||
| if schemas[0].Schema == nil { | ||
| t.Fatal("expected schema to be empty object, got nil") | ||
| } | ||
| if len(schemas[0].Schema) != 0 { | ||
| t.Errorf("expected empty schema object, got %v", schemas[0].Schema) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("invalid base64 returns error", func(t *testing.T) { | ||
| project := &ory.Project{ | ||
| Services: ory.ProjectServices{ | ||
| Identity: &ory.ProjectServiceIdentity{ | ||
| Config: map[string]interface{}{ | ||
| "identity": map[string]interface{}{ | ||
| "schemas": []interface{}{ | ||
| map[string]interface{}{ | ||
| "id": "bad-b64", | ||
| "url": "base64://!!!not-valid-base64!!!", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| _, err := extractSchemasFromProjectConfig(project) | ||
| if err == nil { | ||
| t.Fatal("expected error for invalid base64, got nil") | ||
| } | ||
| }) | ||
|
|
||
| t.Run("invalid JSON in base64 returns error", func(t *testing.T) { | ||
| // "not json" in base64 | ||
| project := &ory.Project{ | ||
| Services: ory.ProjectServices{ | ||
| Identity: &ory.ProjectServiceIdentity{ | ||
| Config: map[string]interface{}{ | ||
| "identity": map[string]interface{}{ | ||
| "schemas": []interface{}{ | ||
| map[string]interface{}{ | ||
| "id": "bad-json", | ||
| "url": "base64://bm90IGpzb24=", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| _, err := extractSchemasFromProjectConfig(project) | ||
| if err == nil { | ||
| t.Fatal("expected error for invalid JSON, got nil") | ||
| } | ||
| }) | ||
|
|
||
| t.Run("multiple schemas", func(t *testing.T) { | ||
| b64 := "eyJ0eXBlIjoib2JqZWN0In0=" // {"type":"object"} | ||
| project := &ory.Project{ | ||
| Services: ory.ProjectServices{ | ||
| Identity: &ory.ProjectServiceIdentity{ | ||
| Config: map[string]interface{}{ | ||
| "identity": map[string]interface{}{ | ||
| "schemas": []interface{}{ | ||
| map[string]interface{}{ | ||
| "id": "preset://username", | ||
| "url": "preset://username", | ||
| }, | ||
| map[string]interface{}{ | ||
| "id": "custom-hash-id", | ||
| "url": "base64://" + b64, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| schemas, err := extractSchemasFromProjectConfig(project) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if len(schemas) != 2 { | ||
| t.Fatalf("expected 2 schemas, got %d", len(schemas)) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func TestHasProjectClient(t *testing.T) { | ||
| t.Run("configured", func(t *testing.T) { | ||
| c := &OryClient{config: OryClientConfig{ProjectSlug: "slug", ProjectAPIKey: "key"}} | ||
| if !c.HasProjectClient() { | ||
| t.Error("expected HasProjectClient to return true") | ||
| } | ||
| }) | ||
| t.Run("missing slug", func(t *testing.T) { | ||
| c := &OryClient{config: OryClientConfig{ProjectAPIKey: "key"}} | ||
| if c.HasProjectClient() { | ||
| t.Error("expected HasProjectClient to return false") | ||
| } | ||
| }) | ||
| t.Run("missing key", func(t *testing.T) { | ||
| c := &OryClient{config: OryClientConfig{ProjectSlug: "slug"}} | ||
| if c.HasProjectClient() { | ||
| t.Error("expected HasProjectClient to return false") | ||
| } | ||
| }) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.