Skip to content
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

feat(schema): allow usage of custom schemas #139

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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
6 changes: 6 additions & 0 deletions cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type Config struct {
// Allows usage of popular browser extensions schemas
AllowBrowserExtensions bool

// Allows to add custom schema like tauri://
CustomSchemas []string

// Allows usage of WebSocket protocol
AllowWebSockets bool

Expand Down Expand Up @@ -87,6 +90,9 @@ func (c Config) getAllowedSchemas() []string {
if c.AllowFiles {
allowedSchemas = append(allowedSchemas, FileSchemas...)
}
if c.CustomSchemas != nil {
allowedSchemas = append(allowedSchemas, c.CustomSchemas...)
}
return allowedSchemas
}

Expand Down
16 changes: 16 additions & 0 deletions cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@
assert.True(t, cors.validateOrigin("chrome-extension://random-extension-id"))
}

func TestValidateTauri(t *testing.T) {
c := Config{
AllowOrigins: []string{"tauri://localhost:1234"},
AllowBrowserExtensions: true,
}
err := c.Validate()
assert.Equal(t, err.Error(), "bad origin: origins must contain '*' or include http://,https://,chrome-extension://,safari-extension://,moz-extension://,ms-browser-extension://")

Check failure on line 280 in cors_test.go

View workflow job for this annotation

GitHub Actions / lint

line is 178 characters (lll)

c = Config{
AllowOrigins: []string{"tauri://localhost:1234"},
AllowBrowserExtensions: true,
CustomSchemas: []string{"tauri"},
}
assert.Nil(t, c.Validate())
}

func TestPassesAllowOrigins(t *testing.T) {
router := newTestRouter(Config{
AllowOrigins: []string{"http://google.com"},
Expand Down
Loading