Skip to content

Commit

Permalink
Merge pull request #2021 from ipfs/fix/corsconfig
Browse files Browse the repository at this point in the history
Fix SetAllowedOrigins
  • Loading branch information
jbenet committed Jan 22, 2016
2 parents 9c1375f + f080158 commit ffe6c85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion commands/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ func (cfg ServerConfig) AllowedOrigins() []string {
func (cfg *ServerConfig) SetAllowedOrigins(origins ...string) {
cfg.cORSOptsRWMutex.Lock()
defer cfg.cORSOptsRWMutex.Unlock()
cfg.cORSOpts.AllowedOrigins = origins
o := make([]string, len(origins))
copy(o, origins)
cfg.cORSOpts.AllowedOrigins = o
}

func (cfg *ServerConfig) AppendAllowedOrigins(origins ...string) {
Expand Down
13 changes: 13 additions & 0 deletions test/sharness/t0060-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ test_description="Test daemon command"

. lib/test-lib.sh

gwyport=8080
apiport=5001

# TODO: randomize ports here once we add --config to ipfs daemon

# this needs to be in a different test than "ipfs daemon --init" below
Expand Down Expand Up @@ -44,6 +47,16 @@ test_expect_success "ipfs peer id looks good" '
test_check_peerid "$PEERID"
'

# this is for checking SetAllowedOrigins race condition for the api and gateway
# See https://github.com/ipfs/go-ipfs/pull/1966
test_expect_success "ipfs API works with the correct allowed origin port" '
curl -s -X GET -H "Origin:http://localhost:$apiport" -I "http://localhost:$apiport/api/v0/version"
'

test_expect_success "ipfs gateway works with the correct allowed origin port" '
curl -s -X GET -H "Origin:http://localhost:$gwyport" -I "http://localhost:$gwyport/api/v0/version"
'

# This is like t0020-init.sh "ipfs init output looks good"
#
# Unfortunately the line:
Expand Down

0 comments on commit ffe6c85

Please sign in to comment.