From b9706815b3bd9ef70a13a7d92a12cbd0461b8a02 Mon Sep 17 00:00:00 2001 From: rht Date: Tue, 1 Dec 2015 18:44:17 +0700 Subject: [PATCH 1/2] Fix SetAllowedOrigins License: MIT Signed-off-by: rht --- commands/http/handler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commands/http/handler.go b/commands/http/handler.go index 9f43e4d6e8c..5679cd6e7e2 100644 --- a/commands/http/handler.go +++ b/commands/http/handler.go @@ -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) { From f0801589b46bbd7c96ddba0168376f3443222f16 Mon Sep 17 00:00:00 2001 From: rht Date: Thu, 17 Dec 2015 00:07:10 +0700 Subject: [PATCH 2/2] Add SetAllowedOrigins race test case License: MIT Signed-off-by: rht --- test/sharness/t0060-daemon.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/sharness/t0060-daemon.sh b/test/sharness/t0060-daemon.sh index f793b578096..a5d3f410e59 100755 --- a/test/sharness/t0060-daemon.sh +++ b/test/sharness/t0060-daemon.sh @@ -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 @@ -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: