From 6c58b1e7a62fbcef203a8b94cf5f7b020cb0154b Mon Sep 17 00:00:00 2001 From: Alex Saunders Date: Thu, 23 Nov 2023 11:35:22 +0000 Subject: [PATCH] move appPublicURL to appData and vary CP invite URL by environment --- internal/app/app.go | 1 - internal/page/app_data.go | 1 + internal/page/donor/check_your_lpa.go | 2 +- internal/page/donor/check_your_lpa_test.go | 2 +- internal/page/donor/mock_test.go | 9 +-- internal/page/donor/register.go | 17 +++--- internal/page/donor/register_test.go | 67 +++++++++++----------- 7 files changed, 49 insertions(+), 50 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index 8e8867fe72..00f6e26783 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -185,7 +185,6 @@ func App( attorneyStore, notifyClient, evidenceReceivedStore, - s3Client, documentStore, eventClient, ) diff --git a/internal/page/app_data.go b/internal/page/app_data.go index fded54dec5..d36f6e8d70 100644 --- a/internal/page/app_data.go +++ b/internal/page/app_data.go @@ -26,6 +26,7 @@ type AppData struct { ActorType actor.Type AttorneyID string OneloginURL string + AppPublicURL string } func (d AppData) Redirect(w http.ResponseWriter, r *http.Request, url string) error { diff --git a/internal/page/donor/check_your_lpa.go b/internal/page/donor/check_your_lpa.go index edbab6b8e6..f630bcfdd8 100644 --- a/internal/page/donor/check_your_lpa.go +++ b/internal/page/donor/check_your_lpa.go @@ -53,7 +53,7 @@ func (n *checkYourLpaNotifier) sendPaperNotification(ctx context.Context, appDat } else { sms.TemplateID = n.notifyClient.TemplateID(notify.CertificateProviderPaperMeetingPromptSMS) sms.Personalisation["lpaType"] = appData.Localizer.T(donor.Type.LegalTermTransKey()) - sms.Personalisation["CPLandingPageLink"] = "www.gov.uk/opg/certificate-provider" + sms.Personalisation["CPLandingPageLink"] = appData.AppPublicURL + appData.Lang.URL(page.Paths.CertificateProviderStart.Format()) } _, err := n.notifyClient.Sms(ctx, sms) diff --git a/internal/page/donor/check_your_lpa_test.go b/internal/page/donor/check_your_lpa_test.go index 559d77d4f7..ed5531f301 100644 --- a/internal/page/donor/check_your_lpa_test.go +++ b/internal/page/donor/check_your_lpa_test.go @@ -345,7 +345,7 @@ func TestPostCheckYourLpaPaperCertificateProviderOnFirstCheck(t *testing.T) { "donorFullName": "Teneil Throssell", "lpaType": "property and affairs", "donorFirstNames": "Teneil", - "CPLandingPageLink": "www.gov.uk/opg/certificate-provider", + "CPLandingPageLink": "http://example.org/certificate-provider-start", }, }). Return("", nil) diff --git a/internal/page/donor/mock_test.go b/internal/page/donor/mock_test.go index f5f2819f75..adb1b9c7bd 100644 --- a/internal/page/donor/mock_test.go +++ b/internal/page/donor/mock_test.go @@ -27,10 +27,11 @@ var ( } expectedError = errors.New("err") testAppData = page.AppData{ - SessionID: "session-id", - LpaID: "lpa-id", - Lang: localize.En, - Paths: page.Paths, + SessionID: "session-id", + LpaID: "lpa-id", + Lang: localize.En, + Paths: page.Paths, + AppPublicURL: "http://example.org", } testNow = time.Date(2023, time.July, 3, 4, 5, 6, 1, time.UTC) testNowFn = func() time.Time { return testNow } diff --git a/internal/page/donor/register.go b/internal/page/donor/register.go index e7dde7bc96..28a91cf647 100644 --- a/internal/page/donor/register.go +++ b/internal/page/donor/register.go @@ -175,7 +175,6 @@ func Register( attorneyStore AttorneyStore, notifyClient NotifyClient, evidenceReceivedStore EvidenceReceivedStore, - evidenceS3Client S3Client, documentStore DocumentStore, eventClient EventClient, ) { @@ -184,11 +183,10 @@ func Register( sessionStore: sessionStore, donorStore: donorStore, payClient: payClient, - appPublicURL: appPublicURL, randomString: random.String, } - handleRoot := makeHandle(rootMux, sessionStore, None, errorHandler) + handleRoot := makeHandle(rootMux, sessionStore, None, errorHandler, appPublicURL) handleRoot(page.Paths.Login, None, page.Login(logger, oneLoginClient, sessionStore, random.String, page.Paths.LoginCallback)) @@ -198,8 +196,8 @@ func Register( lpaMux := http.NewServeMux() rootMux.Handle("/lpa/", page.RouteToPrefix("/lpa/", lpaMux, notFoundHandler)) - handleDonor := makeHandle(lpaMux, sessionStore, RequireSession, errorHandler) - handleWithDonor := makeLpaHandle(lpaMux, sessionStore, RequireSession, errorHandler, donorStore) + handleDonor := makeHandle(lpaMux, sessionStore, RequireSession, errorHandler, appPublicURL) + handleWithDonor := makeLpaHandle(lpaMux, sessionStore, RequireSession, errorHandler, donorStore, appPublicURL) handleDonor(page.Paths.Root, None, notFoundHandler) @@ -391,7 +389,7 @@ const ( CanGoBack ) -func makeHandle(mux *http.ServeMux, store sesh.Store, defaultOptions handleOpt, errorHandler page.ErrorHandler) func(page.Path, handleOpt, page.Handler) { +func makeHandle(mux *http.ServeMux, store sesh.Store, defaultOptions handleOpt, errorHandler page.ErrorHandler, appPublicURL string) func(page.Path, handleOpt, page.Handler) { return func(path page.Path, opt handleOpt, h page.Handler) { opt = opt | defaultOptions @@ -402,6 +400,7 @@ func makeHandle(mux *http.ServeMux, store sesh.Store, defaultOptions handleOpt, appData.Page = path.Format() appData.CanGoBack = opt&CanGoBack != 0 appData.ActorType = actor.TypeDonor + appData.AppPublicURL = appPublicURL if opt&RequireSession != 0 { donorSession, err := sesh.Login(store, r) @@ -431,7 +430,7 @@ func makeHandle(mux *http.ServeMux, store sesh.Store, defaultOptions handleOpt, } } -func makeLpaHandle(mux *http.ServeMux, store sesh.Store, defaultOptions handleOpt, errorHandler page.ErrorHandler, donorStore DonorStore) func(page.LpaPath, handleOpt, Handler) { +func makeLpaHandle(mux *http.ServeMux, store sesh.Store, defaultOptions handleOpt, errorHandler page.ErrorHandler, donorStore DonorStore, appPublicURL string) func(page.LpaPath, handleOpt, Handler) { return func(path page.LpaPath, opt handleOpt, h Handler) { opt = opt | defaultOptions @@ -442,6 +441,7 @@ func makeLpaHandle(mux *http.ServeMux, store sesh.Store, defaultOptions handleOp appData := page.AppDataFromContext(ctx) appData.CanGoBack = opt&CanGoBack != 0 appData.ActorType = actor.TypeDonor + appData.AppPublicURL = appPublicURL donorSession, err := sesh.Login(store, r) if err != nil { @@ -482,7 +482,6 @@ type payHelper struct { sessionStore sessions.Store donorStore DonorStore payClient PayClient - appPublicURL string randomString func(int) string } @@ -504,7 +503,7 @@ func (p *payHelper) Pay(appData page.AppData, w http.ResponseWriter, r *http.Req Amount: donor.FeeAmount(), Reference: p.randomString(12), Description: "Property and Finance LPA", - ReturnUrl: p.appPublicURL + appData.Lang.URL(page.Paths.PaymentConfirmation.Format(donor.LpaID)), + ReturnUrl: appData.AppPublicURL + appData.Lang.URL(page.Paths.PaymentConfirmation.Format(donor.LpaID)), Email: donor.Donor.Email, Language: appData.Lang.String(), } diff --git a/internal/page/donor/register_test.go b/internal/page/donor/register_test.go index 4b7f794a40..1622a20da1 100644 --- a/internal/page/donor/register_test.go +++ b/internal/page/donor/register_test.go @@ -23,7 +23,7 @@ import ( func TestRegister(t *testing.T) { mux := http.NewServeMux() - Register(mux, &log.Logger{}, template.Templates{}, nil, nil, &onelogin.Client{}, &place.Client{}, "http://public.url", &pay.Client{}, nil, &mockWitnessCodeSender{}, nil, nil, nil, nil, ¬ify.Client{}, nil, nil, nil, nil) + Register(mux, &log.Logger{}, template.Templates{}, nil, nil, &onelogin.Client{}, &place.Client{}, "http://example.org", &pay.Client{}, nil, &mockWitnessCodeSender{}, nil, nil, nil, nil, ¬ify.Client{}, nil, nil, nil) assert.Implements(t, (*http.Handler)(nil), mux) } @@ -38,13 +38,14 @@ func TestMakeHandle(t *testing.T) { Return(&sessions.Session{Values: map[any]any{"session": &sesh.LoginSession{Sub: "random"}}}, nil) mux := http.NewServeMux() - handle := makeHandle(mux, sessionStore, None, nil) + handle := makeHandle(mux, sessionStore, None, nil, "http://example.org") handle("/path", RequireSession|CanGoBack, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { assert.Equal(t, page.AppData{ - Page: "/path", - CanGoBack: true, - SessionID: "cmFuZG9t", - ActorType: actor.TypeDonor, + Page: "/path", + CanGoBack: true, + SessionID: "cmFuZG9t", + ActorType: actor.TypeDonor, + AppPublicURL: "http://example.org", }, appData) assert.Equal(t, w, hw) @@ -72,14 +73,15 @@ func TestMakeHandleExistingSessionData(t *testing.T) { Return(&sessions.Session{Values: map[any]any{"session": &sesh.LoginSession{Sub: "random"}}}, nil) mux := http.NewServeMux() - handle := makeHandle(mux, sessionStore, None, nil) + handle := makeHandle(mux, sessionStore, None, nil, "http://example.org") handle("/path", RequireSession|CanGoBack, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { assert.Equal(t, page.AppData{ - Page: "/path", - SessionID: "cmFuZG9t", - CanGoBack: true, - LpaID: "123", - ActorType: actor.TypeDonor, + Page: "/path", + SessionID: "cmFuZG9t", + CanGoBack: true, + LpaID: "123", + ActorType: actor.TypeDonor, + AppPublicURL: "http://example.org", }, appData) assert.Equal(t, w, hw) @@ -110,7 +112,7 @@ func TestMakeHandleErrors(t *testing.T) { Return(&sessions.Session{Values: map[any]any{"session": &sesh.LoginSession{Sub: "random"}}}, nil) mux := http.NewServeMux() - handle := makeHandle(mux, sessionStore, None, errorHandler.Execute) + handle := makeHandle(mux, sessionStore, None, errorHandler.Execute, "") handle("/path", RequireSession, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { return expectedError }) @@ -128,7 +130,7 @@ func TestMakeHandleSessionError(t *testing.T) { Return(&sessions.Session{}, expectedError) mux := http.NewServeMux() - handle := makeHandle(mux, sessionStore, None, nil) + handle := makeHandle(mux, sessionStore, None, nil, "") handle("/path", RequireSession, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { return nil }) mux.ServeHTTP(w, r) @@ -148,7 +150,7 @@ func TestMakeHandleSessionMissing(t *testing.T) { Return(&sessions.Session{Values: map[any]any{}}, nil) mux := http.NewServeMux() - handle := makeHandle(mux, sessionStore, None, nil) + handle := makeHandle(mux, sessionStore, None, nil, "") handle("/path", RequireSession, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { return nil }) mux.ServeHTTP(w, r) @@ -163,7 +165,7 @@ func TestMakeHandleNoSessionRequired(t *testing.T) { r, _ := http.NewRequest(http.MethodGet, "/path", nil) mux := http.NewServeMux() - handle := makeHandle(mux, nil, None, nil) + handle := makeHandle(mux, nil, None, nil, "") handle("/path", None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { assert.Equal(t, page.AppData{ Page: "/path", @@ -206,12 +208,13 @@ func TestMakeLpaHandleWhenDetailsProvidedAndUIDExists(t *testing.T) { LpaUID: "a-uid", }, nil) - handle := makeLpaHandle(mux, sessionStore, RequireSession, nil, donorStore) + handle := makeLpaHandle(mux, sessionStore, RequireSession, nil, donorStore, "http://example.org") handle("/path", None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, _ *actor.DonorProvidedDetails) error { assert.Equal(t, page.AppData{ - Page: "/lpa//path", - ActorType: actor.TypeDonor, - SessionID: "cmFuZG9t", + Page: "/lpa//path", + ActorType: actor.TypeDonor, + SessionID: "cmFuZG9t", + AppPublicURL: "http://example.org", }, appData) assert.Equal(t, w, hw) @@ -240,7 +243,7 @@ func TestMakeLpaHandleWhenSessionStoreError(t *testing.T) { On("Get", r, "session"). Return(&sessions.Session{}, expectedError) - handle := makeLpaHandle(mux, sessionStore, RequireSession, nil, nil) + handle := makeLpaHandle(mux, sessionStore, RequireSession, nil, nil, "") handle("/path", None, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *actor.DonorProvidedDetails) error { return expectedError }) @@ -272,7 +275,7 @@ func TestMakeLpaHandleWhenLpaStoreError(t *testing.T) { errorHandler. On("Execute", w, r, expectedError) - handle := makeLpaHandle(mux, sessionStore, RequireSession, errorHandler.Execute, donorStore) + handle := makeLpaHandle(mux, sessionStore, RequireSession, errorHandler.Execute, donorStore, "") handle("/path", None, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *actor.DonorProvidedDetails) error { return expectedError }) @@ -299,14 +302,15 @@ func TestMakeLpaHandleSessionExistingSessionData(t *testing.T) { Return(&actor.DonorProvidedDetails{}, nil) mux := http.NewServeMux() - handle := makeLpaHandle(mux, sessionStore, None, nil, donorStore) + handle := makeLpaHandle(mux, sessionStore, None, nil, donorStore, "http://example.org") handle("/path", RequireSession|CanGoBack, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, _ *actor.DonorProvidedDetails) error { assert.Equal(t, page.AppData{ - Page: "/lpa/123/path", - SessionID: "cmFuZG9t", - CanGoBack: true, - LpaID: "123", - ActorType: actor.TypeDonor, + Page: "/lpa/123/path", + SessionID: "cmFuZG9t", + CanGoBack: true, + LpaID: "123", + ActorType: actor.TypeDonor, + AppPublicURL: "http://example.org", }, appData) assert.Equal(t, w, hw) @@ -342,7 +346,7 @@ func TestMakeLpaHandleErrors(t *testing.T) { Return(&actor.DonorProvidedDetails{}, nil) mux := http.NewServeMux() - handle := makeLpaHandle(mux, sessionStore, None, errorHandler.Execute, donorStore) + handle := makeLpaHandle(mux, sessionStore, None, errorHandler.Execute, donorStore, "") handle("/path", RequireSession, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *actor.DonorProvidedDetails) error { return expectedError }) @@ -408,7 +412,6 @@ func TestPayHelperPay(t *testing.T) { err := (&payHelper{ sessionStore: sessionStore, payClient: payClient, - appPublicURL: "http://example.org", randomString: func(int) string { return "123456789012" }, }).Pay(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", Donor: actor.Donor{Email: "a@b.com"}, FeeType: pay.FullFee}) resp := w.Result() @@ -602,7 +605,6 @@ func TestPayHelperPayWhenFeeDenied(t *testing.T) { sessionStore: sessionStore, donorStore: donorStore, payClient: payClient, - appPublicURL: "http://example.org", randomString: func(int) string { return "123456789012" }, }).Pay(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", @@ -672,7 +674,6 @@ func TestPayHelperPayWhenFeeDeniedAndPutStoreError(t *testing.T) { sessionStore: sessionStore, donorStore: donorStore, payClient: payClient, - appPublicURL: "http://example.org", randomString: func(int) string { return "123456789012" }, }).Pay(testAppData, w, r, &actor.DonorProvidedDetails{ LpaID: "lpa-id", @@ -703,7 +704,6 @@ func TestPayHelperPayWhenCreatePaymentErrors(t *testing.T) { err := (&payHelper{ logger: logger, payClient: payClient, - appPublicURL: "http://example.org", randomString: func(int) string { return "123456789012" }, }).Pay(testAppData, w, r, &actor.DonorProvidedDetails{}) @@ -734,7 +734,6 @@ func TestPayHelperPayWhenSessionErrors(t *testing.T) { err := (&payHelper{ sessionStore: sessionStore, payClient: payClient, - appPublicURL: "http://example.org", randomString: func(int) string { return "123456789012" }, }).Pay(testAppData, w, r, &actor.DonorProvidedDetails{})