From f3ddb8306f424bd805643826f6ee33da40ea8f27 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Fri, 29 Jan 2021 11:50:08 +1100 Subject: Update notes and test --- internal/source/gitlab/client/client.go | 6 +++--- test/acceptance/serving_test.go | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/source/gitlab/client/client.go b/internal/source/gitlab/client/client.go index c4e6ebf2..98939641 100644 --- a/internal/source/gitlab/client/client.go +++ b/internal/source/gitlab/client/client.go @@ -25,9 +25,9 @@ import ( const ConnectionErrorMsg = "failed to connect to internal Pages API" // ErrUnauthorizedAPI is returned when resolving a domain with the GitLab API -// returns a http.StatusUnauthorized. This is an edge case when `domain-config-source=auto` -// and there are multiple instances of GitLab Rails and GitLab Pages running. -// See https://gitlab.com/gitlab-org/gitlab-pages/-/issues/535 for more info +// returns a http.StatusUnauthorized. This happens if the common secret file +// is not synced between gitlab-pages and gitlab-rails servers. +// See https://gitlab.com/gitlab-org/gitlab-pages/-/issues/535 for more details. var ErrUnauthorizedAPI = errors.New("pages endpoint unauthorized") // Client is a HTTP client to access Pages internal API diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go index 1c898085..eb9a8023 100644 --- a/test/acceptance/serving_test.go +++ b/test/acceptance/serving_test.go @@ -520,11 +520,11 @@ func TestDomainsSource(t *testing.T) { // The first request will fail and display an error but subsequent requests will // serve from disk source when `domain-config-source=auto` func TestGitLabSourceBecomesUnauthorized(t *testing.T) { - opts := stubOpts{ + opts := &stubOpts{ // edge case https://gitlab.com/gitlab-org/gitlab-pages/-/issues/535 pagesStatusResponse: http.StatusUnauthorized, } - source := NewGitlabDomainsSourceStub(t, &opts) + source := NewGitlabDomainsSourceStub(t, opts) defer source.Close() gitLabAPISecretKey := CreateGitLabAPISecretKeyFixtureFile(t) @@ -537,21 +537,22 @@ func TestGitLabSourceBecomesUnauthorized(t *testing.T) { failedResponse, err := GetPageFromListener(t, httpListener, domain, "/") require.NoError(t, err) + require.True(t, opts.apiCalled, "API should be called") require.Equal(t, http.StatusBadGateway, failedResponse.StatusCode, "first response should fail with 502") // make request again + opts.apiCalled = false + response, err := GetPageFromListener(t, httpListener, domain, "/") require.NoError(t, err) defer response.Body.Close() + require.False(t, opts.apiCalled, "API should not be called after the first failure") require.Equal(t, http.StatusOK, response.StatusCode, "second response should succeed") - require.True(t, opts.apiCalled, "api called mismatch") body, err := ioutil.ReadAll(response.Body) require.NoError(t, err) require.Equal(t, "main-dir\n", string(body), "content mismatch") - - require.True(t, opts.apiCalled, "api called mismatch") } func TestKnownHostInReverseProxySetupReturns200(t *testing.T) { -- cgit v1.2.3