Skip to content

Commit eac6c48

Browse files
authored
feat(schema): allow usage of custom schemas (#139)
1 parent 27b723a commit eac6c48

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

cors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ type Config struct {
5151
// Allows usage of popular browser extensions schemas
5252
AllowBrowserExtensions bool
5353

54+
// Allows to add custom schema like tauri://
55+
CustomSchemas []string
56+
5457
// Allows usage of WebSocket protocol
5558
AllowWebSockets bool
5659

@@ -87,6 +90,9 @@ func (c Config) getAllowedSchemas() []string {
8790
if c.AllowFiles {
8891
allowedSchemas = append(allowedSchemas, FileSchemas...)
8992
}
93+
if c.CustomSchemas != nil {
94+
allowedSchemas = append(allowedSchemas, c.CustomSchemas...)
95+
}
9096
return allowedSchemas
9197
}
9298

cors_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,22 @@ func TestValidateOrigin(t *testing.T) {
271271
assert.True(t, cors.validateOrigin("chrome-extension://random-extension-id"))
272272
}
273273

274+
func TestValidateTauri(t *testing.T) {
275+
c := Config{
276+
AllowOrigins: []string{"tauri://localhost:1234"},
277+
AllowBrowserExtensions: true,
278+
}
279+
err := c.Validate()
280+
assert.Equal(t, err.Error(), "bad origin: origins must contain '*' or include http://,https://,chrome-extension://,safari-extension://,moz-extension://,ms-browser-extension://")
281+
282+
c = Config{
283+
AllowOrigins: []string{"tauri://localhost:1234"},
284+
AllowBrowserExtensions: true,
285+
CustomSchemas: []string{"tauri"},
286+
}
287+
assert.Nil(t, c.Validate())
288+
}
289+
274290
func TestPassesAllowOrigins(t *testing.T) {
275291
router := newTestRouter(Config{
276292
AllowOrigins: []string{"http://google.com"},

0 commit comments

Comments
 (0)