Skip to content

Commit

Permalink
move appPublicURL to appData and vary CP invite URL by environment
Browse files Browse the repository at this point in the history
  • Loading branch information
acsauk committed Nov 23, 2023
1 parent a007060 commit 6c58b1e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 50 deletions.
1 change: 0 additions & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ func App(
attorneyStore,
notifyClient,
evidenceReceivedStore,
s3Client,
documentStore,
eventClient,
)
Expand Down
1 change: 1 addition & 0 deletions internal/page/app_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/page/donor/check_your_lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/page/donor/check_your_lpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions internal/page/donor/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
17 changes: 8 additions & 9 deletions internal/page/donor/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func Register(
attorneyStore AttorneyStore,
notifyClient NotifyClient,
evidenceReceivedStore EvidenceReceivedStore,
evidenceS3Client S3Client,
documentStore DocumentStore,
eventClient EventClient,
) {
Expand All @@ -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))
Expand All @@ -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)

Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -482,7 +482,6 @@ type payHelper struct {
sessionStore sessions.Store
donorStore DonorStore
payClient PayClient
appPublicURL string
randomString func(int) string
}

Expand All @@ -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(),
}
Expand Down
67 changes: 33 additions & 34 deletions internal/page/donor/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &notify.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, &notify.Client{}, nil, nil, nil)

assert.Implements(t, (*http.Handler)(nil), mux)
}
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
})
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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
})
Expand All @@ -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)

Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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: "[email protected]"}, FeeType: pay.FullFee})
resp := w.Result()
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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{})

Expand Down Expand Up @@ -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{})

Expand Down

0 comments on commit 6c58b1e

Please sign in to comment.