diff --git a/api/checks/api.go b/api/checks/api.go index ff6ffee7ea2..4e749a0e693 100644 --- a/api/checks/api.go +++ b/api/checks/api.go @@ -166,7 +166,7 @@ func (s checksAPIImpl) CreateWPTCheckSuite(appID, installationID int64, sha stri func (s checksAPIImpl) GetWPTRepoAppInstallationIDs() (appID, installationID int64) { // Production - if s.GetHostname() == "wpt.fyi" { + if s.GetOrigin().Hostname() == "wpt.fyi" { return wptfyiCheckAppID, wptRepoInstallationID } // Default to staging diff --git a/api/checks/mock_checks/api_mock.go b/api/checks/mock_checks/api_mock.go index 49b68e40d73..292e3e8970b 100644 --- a/api/checks/mock_checks/api_mock.go +++ b/api/checks/mock_checks/api_mock.go @@ -130,18 +130,18 @@ func (mr *MockAPIMockRecorder) GetHTTPClientWithTimeout(arg0 interface{}) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHTTPClientWithTimeout", reflect.TypeOf((*MockAPI)(nil).GetHTTPClientWithTimeout), arg0) } -// GetHostname mocks base method. -func (m *MockAPI) GetHostname() string { +// GetOrigin mocks base method. +func (m *MockAPI) GetOrigin() *url.URL { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetHostname") - ret0, _ := ret[0].(string) + ret := m.ctrl.Call(m, "GetOrigin") + ret0, _ := ret[0].(*url.URL) return ret0 } -// GetHostname indicates an expected call of GetHostname. -func (mr *MockAPIMockRecorder) GetHostname() *gomock.Call { +// GetOrigin indicates an expected call of GetOrigin. +func (mr *MockAPIMockRecorder) GetOrigin() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHostname", reflect.TypeOf((*MockAPI)(nil).GetHostname)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrigin", reflect.TypeOf((*MockAPI)(nil).GetOrigin)) } // GetResultsURL mocks base method. @@ -244,18 +244,18 @@ func (mr *MockAPIMockRecorder) GetVersion() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVersion", reflect.TypeOf((*MockAPI)(nil).GetVersion)) } -// GetVersionedHostname mocks base method. -func (m *MockAPI) GetVersionedHostname() string { +// GetVersionedOrigin mocks base method. +func (m *MockAPI) GetVersionedOrigin() *url.URL { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetVersionedHostname") - ret0, _ := ret[0].(string) + ret := m.ctrl.Call(m, "GetVersionedOrigin") + ret0, _ := ret[0].(*url.URL) return ret0 } -// GetVersionedHostname indicates an expected call of GetVersionedHostname. -func (mr *MockAPIMockRecorder) GetVersionedHostname() *gomock.Call { +// GetVersionedOrigin indicates an expected call of GetVersionedOrigin. +func (mr *MockAPIMockRecorder) GetVersionedOrigin() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVersionedHostname", reflect.TypeOf((*MockAPI)(nil).GetVersionedHostname)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVersionedOrigin", reflect.TypeOf((*MockAPI)(nil).GetVersionedOrigin)) } // GetWPTRepoAppInstallationIDs mocks base method. diff --git a/api/checks/update.go b/api/checks/update.go index 33a053629f7..9f2c2513c2d 100644 --- a/api/checks/update.go +++ b/api/checks/update.go @@ -189,9 +189,9 @@ func getDiffSummary(aeAPI shared.AppEngineAPI, diffAPI shared.DiffAPI, suite sha } diffURL := diffAPI.GetDiffURL(baseRun, headRun, &diffFilter) - host := aeAPI.GetHostname() + origin := aeAPI.GetOrigin() checkState := summaries.CheckState{ - HostName: host, + HostName: origin.Host, TestRun: &headRun, Product: checkProduct, HeadSHA: headRun.FullRevisionHash, @@ -231,7 +231,7 @@ func getDiffSummary(aeAPI shared.AppEngineAPI, diffAPI shared.DiffAPI, suite sha resultsComparison := summaries.ResultsComparison{ BaseRun: baseRun, HeadRun: headRun, - HostURL: fmt.Sprintf("https://%s/", host), + HostURL: origin.Host, DiffURL: diffURL.String(), } if headRun.LabelsSet().Contains(shared.PRHeadLabel) { diff --git a/api/checks/update_test.go b/api/checks/update_test.go index 2407cff06d7..ec9e3da6ba2 100644 --- a/api/checks/update_test.go +++ b/api/checks/update_test.go @@ -31,7 +31,8 @@ func TestGetDiffSummary_Regressed(t *testing.T) { aeAPI.EXPECT().Context().AnyTimes().Return(context.Background()) aeAPI.EXPECT().IsFeatureEnabled(onlyChangesAsRegressionsFeature).Return(enabled) aeAPI.EXPECT().IsFeatureEnabled(failChecksOnRegressionFeature).Return(false) - aeAPI.EXPECT().GetHostname() + origin, _ := url.Parse("https://some-origin.com") + aeAPI.EXPECT().GetOrigin().Return(origin) diffAPI := sharedtest.NewMockDiffAPI(mockCtrl) diffAPI.EXPECT().GetRunsDiff(before, after, sharedtest.SameDiffFilter("ADC"), gomock.Any()).Return(runDiff, nil) if enabled { @@ -49,6 +50,7 @@ func TestGetDiffSummary_Regressed(t *testing.T) { _, ok := summary.(summaries.Regressed) assert.True(t, ok) assert.Equal(t, suite.PRNumbers, summary.GetCheckState().PRNumbers) + assert.Equal(t, "some-origin.com", summary.GetCheckState().HostName) }) } testSummary(false) @@ -68,7 +70,10 @@ func TestGetDiffSummary_Completed(t *testing.T) { aeAPI.EXPECT().Context().AnyTimes().Return(context.Background()) aeAPI.EXPECT().IsFeatureEnabled(onlyChangesAsRegressionsFeature).Return(false) aeAPI.EXPECT().IsFeatureEnabled(failChecksOnRegressionFeature).Return(false) - aeAPI.EXPECT().GetHostname() + aeAPI.EXPECT().GetOrigin().Return(&url.URL{ + Scheme: "https", + Host: "example.com", + }) diffAPI := sharedtest.NewMockDiffAPI(mockCtrl) diffAPI.EXPECT().GetRunsDiff(before, after, gomock.Any(), gomock.Any()).Return(runDiff, nil) diffURL, _ := url.Parse("https://wpt.fyi/results?diff") @@ -83,6 +88,7 @@ func TestGetDiffSummary_Completed(t *testing.T) { _, ok := summary.(summaries.Completed) assert.True(t, ok) assert.Equal(t, suite.PRNumbers, summary.GetCheckState().PRNumbers) + assert.Equal(t, "example.com", summary.GetCheckState().HostName) } func getBeforeAndAfterRuns() (before, after shared.TestRun) { diff --git a/api/receiver/client/client.go b/api/receiver/client/client.go index 1e51b8a899e..6da3046ffdd 100644 --- a/api/receiver/client/client.go +++ b/api/receiver/client/client.go @@ -11,6 +11,7 @@ import ( "io/ioutil" "net/http" "net/url" + "path" "strings" "time" @@ -67,8 +68,10 @@ func (c client) CreateRun( payload.Add("labels", strings.Join(labels, ",")) } // Ensure we call back to this appengine version instance. - host := c.aeAPI.GetVersionedHostname() - payload.Add("callback_url", fmt.Sprintf("https://%s/api/results/create", host)) + u := c.aeAPI.GetVersionedOrigin() + u.Path = path.Join(u.Path, "/api/results/create") + + payload.Add("callback_url", u.String()) uploadURL := c.aeAPI.GetResultsUploadURL() req, err := http.NewRequest("POST", uploadURL.String(), strings.NewReader(payload.Encode())) diff --git a/api/receiver/client/client_test.go b/api/receiver/client/client_test.go index 7bc217a309a..e0f3c4fa0ae 100644 --- a/api/receiver/client/client_test.go +++ b/api/receiver/client/client_test.go @@ -29,6 +29,7 @@ func TestCreateRun(t *testing.T) { assert.Nil(t, r.ParseForm()) assert.Equal(t, []string{"https://wpt.fyi/results.json.gz"}, r.PostForm["result_url"]) assert.Equal(t, []string{"https://wpt.fyi/screenshots.db.gz"}, r.PostForm["screenshot_url"]) + assert.Equal(t, []string{"http://localhost:8080/api/results/create"}, r.PostForm["callback_url"]) assert.Equal(t, "foo,bar", r.PostForm.Get("labels")) w.Write([]byte("OK")) visited = true @@ -41,7 +42,9 @@ func TestCreateRun(t *testing.T) { defer mockC.Finish() aeAPI := sharedtest.NewMockAppEngineAPI(mockC) gomock.InOrder( - aeAPI.EXPECT().GetVersionedHostname().Return("localhost:8080"), + aeAPI.EXPECT().GetVersionedOrigin().Return(&url.URL{ + Scheme: "http", + Host: "localhost:8080"}), aeAPI.EXPECT().GetResultsUploadURL().Return(serverURL), aeAPI.EXPECT().GetHTTPClientWithTimeout(UploadTimeout).Return(server.Client()), ) diff --git a/api/receiver/mock_receiver/api_mock.go b/api/receiver/mock_receiver/api_mock.go index f963887af3e..388cf57532c 100644 --- a/api/receiver/mock_receiver/api_mock.go +++ b/api/receiver/mock_receiver/api_mock.go @@ -112,18 +112,18 @@ func (mr *MockAPIMockRecorder) GetHTTPClientWithTimeout(arg0 interface{}) *gomoc return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHTTPClientWithTimeout", reflect.TypeOf((*MockAPI)(nil).GetHTTPClientWithTimeout), arg0) } -// GetHostname mocks base method. -func (m *MockAPI) GetHostname() string { +// GetOrigin mocks base method. +func (m *MockAPI) GetOrigin() *url.URL { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetHostname") - ret0, _ := ret[0].(string) + ret := m.ctrl.Call(m, "GetOrigin") + ret0, _ := ret[0].(*url.URL) return ret0 } -// GetHostname indicates an expected call of GetHostname. -func (mr *MockAPIMockRecorder) GetHostname() *gomock.Call { +// GetOrigin indicates an expected call of GetOrigin. +func (mr *MockAPIMockRecorder) GetOrigin() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHostname", reflect.TypeOf((*MockAPI)(nil).GetHostname)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrigin", reflect.TypeOf((*MockAPI)(nil).GetOrigin)) } // GetResultsURL mocks base method. @@ -211,18 +211,18 @@ func (mr *MockAPIMockRecorder) GetVersion() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVersion", reflect.TypeOf((*MockAPI)(nil).GetVersion)) } -// GetVersionedHostname mocks base method. -func (m *MockAPI) GetVersionedHostname() string { +// GetVersionedOrigin mocks base method. +func (m *MockAPI) GetVersionedOrigin() *url.URL { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetVersionedHostname") - ret0, _ := ret[0].(string) + ret := m.ctrl.Call(m, "GetVersionedOrigin") + ret0, _ := ret[0].(*url.URL) return ret0 } -// GetVersionedHostname indicates an expected call of GetVersionedHostname. -func (mr *MockAPIMockRecorder) GetVersionedHostname() *gomock.Call { +// GetVersionedOrigin indicates an expected call of GetVersionedOrigin. +func (mr *MockAPIMockRecorder) GetVersionedOrigin() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVersionedHostname", reflect.TypeOf((*MockAPI)(nil).GetVersionedHostname)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVersionedOrigin", reflect.TypeOf((*MockAPI)(nil).GetVersionedOrigin)) } // IsAdmin mocks base method. diff --git a/api/screenshot/cache.go b/api/screenshot/cache.go index f512b69c0e9..918761ace2b 100644 --- a/api/screenshot/cache.go +++ b/api/screenshot/cache.go @@ -63,7 +63,7 @@ func uploadScreenshotHandler(w http.ResponseWriter, r *http.Request) { return } bucketName := "wptd-screenshots-staging" - if aeAPI.GetHostname() == "wpt.fyi" { + if aeAPI.GetOrigin().Hostname() == "wpt.fyi" { bucketName = "wptd-screenshots" } bucket := gcs.Bucket(bucketName) diff --git a/api/screenshot_redirect_handler.go b/api/screenshot_redirect_handler.go index ffcfc6d555c..2989a18969d 100644 --- a/api/screenshot_redirect_handler.go +++ b/api/screenshot_redirect_handler.go @@ -26,7 +26,7 @@ func apiScreenshotRedirectHandler(w http.ResponseWriter, r *http.Request) { ctx := r.Context() aeAPI := shared.NewAppEngineAPI(ctx) bucket := "wptd-screenshots-staging" - if aeAPI.GetHostname() == "wpt.fyi" { + if aeAPI.GetOrigin().Hostname() == "wpt.fyi" { bucket = "wptd-screenshots" } url := fmt.Sprintf("https://storage.googleapis.com/%s/%s.png", bucket, shot) diff --git a/api/taskcluster/webhook_test.go b/api/taskcluster/webhook_test.go index bc89bf71fe5..489e2facdd8 100644 --- a/api/taskcluster/webhook_test.go +++ b/api/taskcluster/webhook_test.go @@ -34,6 +34,16 @@ func strPtr(s string) *string { return &s } +func testOrigin() *url.URL { + // Because these tests call the function multiple times, we need to use + // DoAndReturn and pass this function for the mock assertion. + // Without it, it will append the path to the same pointer + u := new(url.URL) + u.Scheme = "http" + u.Host = "localhost:8080" + return u +} + func TestShouldProcessStatus_states(t *testing.T) { status := tc.StatusEventPayload{} status.State = strPtr("success") @@ -250,6 +260,8 @@ func TestCreateAllRuns_success(t *testing.T) { var requested uint32 requested = 0 handler := func(w http.ResponseWriter, r *http.Request) { + assert.Nil(t, r.ParseForm()) + assert.Equal(t, []string{"http://localhost:8080/api/results/create"}, r.PostForm["callback_url"]) atomic.AddUint32(&requested, 1) w.Write([]byte("OK")) } @@ -261,7 +273,8 @@ func TestCreateAllRuns_success(t *testing.T) { mockC := gomock.NewController(t) defer mockC.Finish() aeAPI := sharedtest.NewMockAppEngineAPI(mockC) - aeAPI.EXPECT().GetVersionedHostname().AnyTimes().Return("localhost:8080") + + aeAPI.EXPECT().GetVersionedOrigin().MinTimes(1).DoAndReturn(testOrigin) aeAPI.EXPECT().GetHTTPClientWithTimeout(uc.UploadTimeout).AnyTimes().Return(server.Client()) aeAPI.EXPECT().GetResultsUploadURL().AnyTimes().Return(serverURL) @@ -308,6 +321,8 @@ func TestCreateAllRuns_one_error(t *testing.T) { var requested uint32 requested = 0 handler := func(w http.ResponseWriter, r *http.Request) { + assert.Nil(t, r.ParseForm()) + assert.Equal(t, []string{"http://localhost:8080/api/results/create"}, r.PostForm["callback_url"]) if atomic.CompareAndSwapUint32(&requested, 0, 1) { w.Write([]byte("OK")) } else if atomic.CompareAndSwapUint32(&requested, 1, 2) { @@ -324,7 +339,7 @@ func TestCreateAllRuns_one_error(t *testing.T) { sha := "abcdef1234abcdef1234abcdef1234abcdef1234" aeAPI := sharedtest.NewMockAppEngineAPI(mockC) - aeAPI.EXPECT().GetVersionedHostname().MinTimes(1).Return("localhost:8080") + aeAPI.EXPECT().GetVersionedOrigin().MinTimes(1).DoAndReturn(testOrigin) aeAPI.EXPECT().GetHTTPClientWithTimeout(uc.UploadTimeout).Times(2).Return(server.Client()) serverURL, _ := url.Parse(server.URL) aeAPI.EXPECT().GetResultsUploadURL().AnyTimes().Return(serverURL) @@ -349,6 +364,8 @@ func TestCreateAllRuns_one_error(t *testing.T) { func TestCreateAllRuns_all_errors(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { + assert.Nil(t, r.ParseForm()) + assert.Equal(t, []string{"http://localhost:8080/api/results/create"}, r.PostForm["callback_url"]) time.Sleep(time.Second * 2) } server := httptest.NewServer(http.HandlerFunc(handler)) @@ -359,7 +376,7 @@ func TestCreateAllRuns_all_errors(t *testing.T) { sha := "abcdef1234abcdef1234abcdef1234abcdef1234" aeAPI := sharedtest.NewMockAppEngineAPI(mockC) - aeAPI.EXPECT().GetVersionedHostname().MinTimes(1).Return("localhost:8080") + aeAPI.EXPECT().GetVersionedOrigin().MinTimes(1).DoAndReturn(testOrigin) // Give a very short timeout (instead of the asked 1min) to make tests faster. aeAPI.EXPECT().GetHTTPClientWithTimeout(uc.UploadTimeout).MinTimes(1).Return(&http.Client{Timeout: time.Microsecond}) serverURL, _ := url.Parse(server.URL) @@ -383,6 +400,8 @@ func TestCreateAllRuns_all_errors(t *testing.T) { func TestCreateAllRuns_pr_labels_exclude_master(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { + assert.Nil(t, r.ParseForm()) + assert.Equal(t, []string{"http://localhost:8080/api/results/create"}, r.PostForm["callback_url"]) // We should not see a master label here, even though we // specify one in the call to tc.CreateAllRuns. defer r.Body.Close() @@ -398,7 +417,7 @@ func TestCreateAllRuns_pr_labels_exclude_master(t *testing.T) { mockC := gomock.NewController(t) defer mockC.Finish() aeAPI := sharedtest.NewMockAppEngineAPI(mockC) - aeAPI.EXPECT().GetVersionedHostname().AnyTimes().Return("localhost:8080") + aeAPI.EXPECT().GetVersionedOrigin().AnyTimes().DoAndReturn(testOrigin) aeAPI.EXPECT().GetHTTPClientWithTimeout(uc.UploadTimeout).AnyTimes().Return(server.Client()) aeAPI.EXPECT().GetResultsUploadURL().AnyTimes().Return(serverURL) diff --git a/shared/appengine.go b/shared/appengine.go index 9742c8df7a6..c141cd172a0 100644 --- a/shared/appengine.go +++ b/shared/appengine.go @@ -13,6 +13,7 @@ import ( "net/http" "net/url" "os" + "path" "strings" "time" @@ -175,16 +176,16 @@ type AppEngineAPI interface { // GetVersion returns the version name for the current environment. GetVersion() string - // GetHostname returns the canonical hostname for the current AppEngine - // project, i.e. staging.wpt.fyi or wpt.fyi. - GetHostname() string - // GetVersionedHostname returns the AppEngine hostname for the current + // GetOrigin returns the canonical origin for the current AppEngine + // project, i.e. [https|http]://staging.wpt.fyi or [https|http]://wpt.fyi. + GetOrigin() *url.URL + // GetVersionedOrigin returns the AppEngine origin for the current // version of the default service, i.e., - // VERSION-dot-wptdashboard{,-staging}.REGION.r.appspot.com. + // [https|http]://VERSION-dot-wptdashboard{,-staging}.REGION.r.appspot.com. // Note: if the default service does not have the current version, // AppEngine routing will find a version according to traffic split. // https://cloud.google.com/appengine/docs/standard/go/how-requests-are-routed#soft_routing - GetVersionedHostname() string + GetVersionedOrigin() *url.URL // GetServiceHostname returns the AppEngine hostname for the current // version of the given service, i.e., // VERSION-dot-SERVICE-dot-wptdashboard{,-staging}.REGION.r.appspot.com. @@ -302,6 +303,26 @@ func (a appEngineAPIImpl) GetUploader(uploader string) (Uploader, error) { return GetUploader(m, uploader) } +func (a appEngineAPIImpl) GetOrigin() *url.URL { + u := new(url.URL) + u.Scheme = a.getScheme() + u.Host = a.GetHostname() + return u +} +func (a appEngineAPIImpl) GetVersionedOrigin() *url.URL { + u := new(url.URL) + u.Scheme = a.getScheme() + u.Host = a.GetVersionedHostname() + return u +} + +func (a appEngineAPIImpl) getScheme() string { + if runtimeIdentity.application != nil { + return "https" + } + return "http" +} + func (a appEngineAPIImpl) GetHostname() string { if runtimeIdentity.AppID == "wptdashboard" { return "wpt.fyi" @@ -335,15 +356,16 @@ func (a appEngineAPIImpl) GetServiceHostname(service string) string { } func (a appEngineAPIImpl) GetResultsURL(filter TestRunFilter) *url.URL { - return getURL(a.GetHostname(), "/results/", filter) + return getURL(*a.GetOrigin(), "/results/", filter) } func (a appEngineAPIImpl) GetRunsURL(filter TestRunFilter) *url.URL { - return getURL(a.GetHostname(), "/runs", filter) + return getURL(*a.GetOrigin(), "/runs", filter) } func (a appEngineAPIImpl) GetResultsUploadURL() *url.URL { - result, _ := url.Parse(fmt.Sprintf("https://%s%s", a.GetVersionedHostname(), "/api/results/upload")) + result := a.GetVersionedOrigin() + result.Path = path.Join(result.Path, "/api/results/upload") return result } @@ -372,10 +394,10 @@ func (a appEngineAPIImpl) ScheduleTask(queueName, taskName, target string, param return createdTaskName, nil } -func getURL(host, path string, filter TestRunFilter) *url.URL { - detailsURL, _ := url.Parse(fmt.Sprintf("https://%s%s", host, path)) - detailsURL.RawQuery = filter.ToQuery().Encode() - return detailsURL +func getURL(origin url.URL, inputPath string, filter TestRunFilter) *url.URL { + origin.Path += path.Join(origin.Path, inputPath) + origin.RawQuery = filter.ToQuery().Encode() + return &origin } func createTaskRequest(queueName, taskName, target string, params url.Values) (taskPrefix string, req *taskspb.CreateTaskRequest) { diff --git a/shared/run_diff.go b/shared/run_diff.go index e23167440d8..4233cc5a70d 100644 --- a/shared/run_diff.go +++ b/shared/run_diff.go @@ -16,6 +16,7 @@ import ( "io/ioutil" "net/http" "net/url" + "path" "strings" "time" @@ -48,7 +49,8 @@ func NewDiffAPI(ctx context.Context) DiffAPI { } func (d diffAPIImpl) GetDiffURL(before, after TestRun, diffFilter *DiffFilterParam) *url.URL { - detailsURL, _ := url.Parse(fmt.Sprintf("https://%s/results/", d.aeAPI.GetHostname())) + detailsURL := d.aeAPI.GetOrigin() + detailsURL.Path = path.Join(detailsURL.Path, "/results/") query := detailsURL.Query() query.Add("run_id", fmt.Sprintf("%v", before.ID)) query.Add("run_id", fmt.Sprintf("%v", after.ID)) @@ -380,7 +382,8 @@ func (d diffAPIImpl) GetRunsDiff(before, after TestRun, filter DiffFilterParam, } func (d diffAPIImpl) getRunsDiffFromSearchCache(before, after TestRun, filter DiffFilterParam, paths mapset.Set) (diff RunDiff, err error) { - diffURL, _ := url.Parse(fmt.Sprintf("https://%s/api/search", d.aeAPI.GetVersionedHostname())) + diffURL := d.aeAPI.GetVersionedOrigin() + diffURL.Path = path.Join(diffURL.Path, "/api/search") query := diffURL.Query() query.Set("diff", "") query.Set("filter", filter.String()) diff --git a/shared/sharedtest/appengine_mock.go b/shared/sharedtest/appengine_mock.go index 640d8316a4f..97fc07e56fd 100644 --- a/shared/sharedtest/appengine_mock.go +++ b/shared/sharedtest/appengine_mock.go @@ -96,18 +96,18 @@ func (mr *MockAppEngineAPIMockRecorder) GetHTTPClientWithTimeout(arg0 interface{ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHTTPClientWithTimeout", reflect.TypeOf((*MockAppEngineAPI)(nil).GetHTTPClientWithTimeout), arg0) } -// GetHostname mocks base method. -func (m *MockAppEngineAPI) GetHostname() string { +// GetOrigin mocks base method. +func (m *MockAppEngineAPI) GetOrigin() *url.URL { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetHostname") - ret0, _ := ret[0].(string) + ret := m.ctrl.Call(m, "GetOrigin") + ret0, _ := ret[0].(*url.URL) return ret0 } -// GetHostname indicates an expected call of GetHostname. -func (mr *MockAppEngineAPIMockRecorder) GetHostname() *gomock.Call { +// GetOrigin indicates an expected call of GetOrigin. +func (mr *MockAppEngineAPIMockRecorder) GetOrigin() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHostname", reflect.TypeOf((*MockAppEngineAPI)(nil).GetHostname)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrigin", reflect.TypeOf((*MockAppEngineAPI)(nil).GetOrigin)) } // GetResultsURL mocks base method. @@ -195,18 +195,18 @@ func (mr *MockAppEngineAPIMockRecorder) GetVersion() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVersion", reflect.TypeOf((*MockAppEngineAPI)(nil).GetVersion)) } -// GetVersionedHostname mocks base method. -func (m *MockAppEngineAPI) GetVersionedHostname() string { +// GetVersionedOrigin mocks base method. +func (m *MockAppEngineAPI) GetVersionedOrigin() *url.URL { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetVersionedHostname") - ret0, _ := ret[0].(string) + ret := m.ctrl.Call(m, "GetVersionedOrigin") + ret0, _ := ret[0].(*url.URL) return ret0 } -// GetVersionedHostname indicates an expected call of GetVersionedHostname. -func (mr *MockAppEngineAPIMockRecorder) GetVersionedHostname() *gomock.Call { +// GetVersionedOrigin indicates an expected call of GetVersionedOrigin. +func (mr *MockAppEngineAPIMockRecorder) GetVersionedOrigin() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVersionedHostname", reflect.TypeOf((*MockAppEngineAPI)(nil).GetVersionedHostname)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVersionedOrigin", reflect.TypeOf((*MockAppEngineAPI)(nil).GetVersionedOrigin)) } // IsFeatureEnabled mocks base method. diff --git a/webapp/admin_handler.go b/webapp/admin_handler.go index 71ec57946f2..27bb7e9695d 100644 --- a/webapp/admin_handler.go +++ b/webapp/admin_handler.go @@ -9,6 +9,7 @@ import ( "fmt" "io/ioutil" "net/http" + "path" "github.com/web-platform-tests/wpt.fyi/shared" ) @@ -51,10 +52,13 @@ func showAdminUploadForm(a shared.AppEngineAPI, acl shared.GitHubAccessControl, return } + u := a.GetVersionedOrigin() + u.Path = path.Join(u.Path, "/api/results/create") + data := struct { CallbackURL string }{ - CallbackURL: fmt.Sprintf("https://%s/api/results/create", a.GetVersionedHostname()), + CallbackURL: u.String(), } // We don't need user info in this template. RenderTemplate(w, nil, "admin_upload.html", data) @@ -84,7 +88,7 @@ func handleAdminFlags(a shared.AppEngineAPI, ds shared.Datastore, acl shared.Git data := struct { Host string }{ - Host: a.GetHostname(), + Host: a.GetOrigin().Host, } // We don't need user info in this template. RenderTemplate(w, nil, "admin_flags.html", data) diff --git a/webapp/analyzer_handler.go b/webapp/analyzer_handler.go index bcc06b55ff8..94d12af30e3 100644 --- a/webapp/analyzer_handler.go +++ b/webapp/analyzer_handler.go @@ -29,7 +29,7 @@ func analyzerHandler(w http.ResponseWriter, r *http.Request) { ctx := r.Context() aeAPI := shared.NewAppEngineAPI(ctx) bucket := "wptd-screenshots-staging" - if aeAPI.GetHostname() == "wpt.fyi" { + if aeAPI.GetOrigin().Hostname() == "wpt.fyi" { bucket = "wptd-screenshots" }