This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable configuring CORS to remove same-domain requirement (#266)
* enable configuring CORS to remove same-domain requirement fixes #235 * make backendHostname UI option configurable in chart
- Loading branch information
Showing
10 changed files
with
132 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,4 +1,11 @@ | ||
apiVersion: v1 | ||
description: Monocular is a search and discovery front end for Helm Charts Repositories. | ||
name: monocular | ||
version: 0.2.0 | ||
description: Monocular is a search and discovery front end for Helm Charts Repositories. | ||
version: 0.3.0 | ||
appVersion: 0.2.0 | ||
home: https://github.com/helm/monocular | ||
sources: | ||
- https://github.com/helm/monocular | ||
maintainers: | ||
- name: prydonius | ||
email: [email protected] |
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -1,30 +1,63 @@ | ||
package cors | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/arschles/assert" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
var headers = []string{"access-control-allow-headers", "x-xsrf-token"} | ||
var origin = []string{"my-api-server"} | ||
var configFileOk = filepath.Join("..", "testdata", "config.yaml") | ||
var configFileNotOk = filepath.Join("..", "testdata", "bogus_config.yaml") | ||
var configFileNoCors = filepath.Join("..", "testdata", "nocors_config.yaml") | ||
var defaultExpectedCors = Cors{ | ||
AllowedOrigins: []string{"my-api-server"}, | ||
AllowedHeaders: []string{"access-control-allow-headers", "x-xsrf-token"}, | ||
} | ||
|
||
func TestConfigFileDoesNotExist(t *testing.T) { | ||
config, err := Config("no-file") | ||
assert.NoErr(t, err) | ||
assert.Equal(t, config.AllowedHeaders, headers, "Allowed headers") | ||
assert.Equal(t, config.AllowedOrigins, origin, "Default origin") | ||
assert.Equal(t, config.AllowedHeaders, defaultExpectedCors.AllowedHeaders, "Allowed headers") | ||
assert.Equal(t, config.AllowedOrigins, defaultExpectedCors.AllowedOrigins, "Default origin") | ||
} | ||
|
||
// In development environment, CORS has a permissive configuration | ||
func TestConfigDevelopment(t *testing.T) { | ||
origCurrentEnv := currentEnv | ||
currentEnv = func() string { | ||
return "development" | ||
} | ||
defer func() { currentEnv = origCurrentEnv }() | ||
func TestConfigFileDoesNotExistDevelopment(t *testing.T) { | ||
os.Setenv("ENVIRONMENT", "development") | ||
defer func() { os.Unsetenv("ENVIRONMENT") }() | ||
var origin = []string{"*"} | ||
config, err := Config("no-file") | ||
assert.NoErr(t, err) | ||
assert.Equal(t, len(config.AllowedHeaders), 0, "Allowed headers") | ||
assert.Equal(t, config.AllowedOrigins, origin, "Default origin") | ||
} | ||
|
||
func TestConfigFileWithoutCors(t *testing.T) { | ||
cors, err := Config(configFileNoCors) | ||
assert.NoErr(t, err) | ||
assert.Equal(t, cors, defaultExpectedCors, "It returns the default CORS") | ||
} | ||
|
||
func TestConfigFromFile(t *testing.T) { | ||
expected := Cors{ | ||
AllowedOrigins: []string{"http://mymonocular"}, | ||
AllowedHeaders: []string{"access-control-allow-headers", "x-xsrf-token"}, | ||
} | ||
cors, err := Config(configFileOk) | ||
assert.NoErr(t, err) | ||
assert.Equal(t, cors, expected, "It uses the cors from the config file") | ||
} | ||
|
||
// Return err | ||
func TestConfigFromFileInvalid(t *testing.T) { | ||
_, err := Config(configFileNotOk) | ||
assert.ExistsErr(t, err, "File exist but it is not valid") | ||
} | ||
|
||
func TestLoadCorsFromFileDoesNotExist(t *testing.T) { | ||
cors, err := loadCorsFromFile("does not exist") | ||
assert.ExistsErr(t, err, "Can not load the file") | ||
assert.Equal(t, cors, Cors{}, "Returns no cors") | ||
} |
This file contains 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
repos: | ||
- foo | ||
- bar | ||
cors: | ||
- foobar |
This file contains 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 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 @@ | ||
otheroption: foo |