Skip to content

Commit

Permalink
Merge cb7ec7a into f0436ef
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Jan 17, 2025
2 parents f0436ef + cb7ec7a commit baf813b
Show file tree
Hide file tree
Showing 51 changed files with 491 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)

Expand Down Expand Up @@ -40,7 +41,9 @@ func ConfirmDontWantToBeAttorneyLoggedOut(tmpl template.Template, shareCodeStore
}

if r.Method == http.MethodPost {
shareCode, err := shareCodeStore.Get(r.Context(), actor.TypeAttorney, r.URL.Query().Get("referenceNumber"))
code := sharecodedata.HashedFromQuery(r.URL.Query())

shareCode, err := shareCodeStore.Get(r.Context(), actor.TypeAttorney, code)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) {

for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
r, _ := http.NewRequest(http.MethodPost, "/?referenceNumber=123", nil)
r, _ := http.NewRequest(http.MethodPost, "/?code=da4ec3358a10c9b0872eb877953cc7b07af5f4d75e4c1cb0597cbbf41e5dbe35", nil)
w := httptest.NewRecorder()
ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"})

Expand Down Expand Up @@ -188,7 +188,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) {

shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "123").
Get(r.Context(), actor.TypeAttorney, sharecodedata.HashedFromString("abcdef123456")).
Return(shareCodeData, nil)
shareCodeStore.EXPECT().
Delete(r.Context(), shareCodeData).
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) {
}

func TestPostConfirmDontWantToBeAttorneyLoggedOutWhenAttorneyNotFound(t *testing.T) {
r, _ := http.NewRequest(http.MethodPost, "/?referenceNumber=123", nil)
r, _ := http.NewRequest(http.MethodPost, "/?code=da4ec3358a10c9b0872eb877953cc7b07af5f4d75e4c1cb0597cbbf41e5dbe35", nil)
w := httptest.NewRecorder()
ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"})

Expand All @@ -255,7 +255,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOutWhenAttorneyNotFound(t *testing

shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "123").
Get(r.Context(), actor.TypeAttorney, sharecodedata.HashedFromString("abcdef123456")).
Return(shareCodeData, nil)

lpaStoreResolvingService := newMockLpaStoreResolvingService(t)
Expand Down
3 changes: 2 additions & 1 deletion internal/attorney/attorneypage/enter_reference_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/attorney"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)

Expand All @@ -31,7 +32,7 @@ func EnterReferenceNumber(tmpl template.Template, shareCodeStore ShareCodeStore,
data.Errors = data.Form.Validate()

if len(data.Errors) == 0 {
referenceNumber := data.Form.ReferenceNumber
referenceNumber := sharecodedata.HashedFromString(data.Form.ReferenceNumber)

shareCode, err := shareCodeStore.Get(r.Context(), actor.TypeAttorney, referenceNumber)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package attorneypage
import (
"errors"
"net/http"
"net/url"

"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)

Expand All @@ -26,7 +26,7 @@ func EnterReferenceNumberOptOut(tmpl template.Template, shareCodeStore ShareCode
data.Errors = data.Form.Validate()

if data.Errors.None() {
referenceNumber := data.Form.ReferenceNumber
referenceNumber := sharecodedata.HashedFromString(data.Form.ReferenceNumber)

shareCode, err := shareCodeStore.Get(r.Context(), actor.TypeAttorney, referenceNumber)
if err != nil {
Expand All @@ -42,7 +42,7 @@ func EnterReferenceNumberOptOut(tmpl template.Template, shareCodeStore ShareCode
return err
}

return page.PathAttorneyConfirmDontWantToBeAttorneyLoggedOut.RedirectQuery(w, r, appData, url.Values{"referenceNumber": {referenceNumber}})
return page.PathAttorneyConfirmDontWantToBeAttorneyLoggedOut.RedirectQuery(w, r, appData, referenceNumber.Query())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestPostEnterReferenceNumberOptOut(t *testing.T) {

shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Get(r.Context(), actor.TypeAttorney, sharecodedata.HashedFromString("abcdef123456")).
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("session-id")), ActorUID: uid}, nil)

sessionStore := newMockSessionStore(t)
Expand All @@ -88,7 +88,7 @@ func TestPostEnterReferenceNumberOptOut(t *testing.T) {

assert.Nil(t, err)
assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, page.PathAttorneyConfirmDontWantToBeAttorneyLoggedOut.Format()+"?referenceNumber=abcdef123456", resp.Header.Get("Location"))
assert.Equal(t, page.PathAttorneyConfirmDontWantToBeAttorneyLoggedOut.Format()+"?code=da4ec3358a10c9b0872eb877953cc7b07af5f4d75e4c1cb0597cbbf41e5dbe35", resp.Header.Get("Location"))
}

func TestPostEnterReferenceNumberOptOutErrors(t *testing.T) {
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestPostEnterReferenceNumberOptOutOnShareCodeStoreNotFoundError(t *testing.

shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Get(r.Context(), actor.TypeAttorney, sharecodedata.HashedFromString("abcdef123456")).
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("session-id"))}, dynamo.NotFoundError{})

err := EnterReferenceNumberOptOut(template.Execute, shareCodeStore, nil)(testAppData, w, r)
Expand Down
10 changes: 5 additions & 5 deletions internal/attorney/attorneypage/enter_reference_number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestPostEnterReferenceNumber(t *testing.T) {

shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Get(r.Context(), actor.TypeAttorney, sharecodedata.HashedFromString("abcdef123456")).
Return(tc.shareCode, nil)

attorneyStore := newMockAttorneyStore(t)
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestPostEnterReferenceNumberOnDonorStoreError(t *testing.T) {

shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Get(r.Context(), actor.TypeAttorney, sharecodedata.HashedFromString("abcdef123456")).
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, expectedError)

err := EnterReferenceNumber(nil, shareCodeStore, nil, nil)(testAppData, w, r)
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestPostEnterReferenceNumberOnShareCodeStoreNotFoundError(t *testing.T) {

shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Get(r.Context(), actor.TypeAttorney, sharecodedata.HashedFromString("abcdef123456")).
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, dynamo.NotFoundError{})

err := EnterReferenceNumber(template.Execute, shareCodeStore, nil, nil)(testAppData, w, r)
Expand All @@ -206,7 +206,7 @@ func TestPostEnterReferenceNumberOnSessionGetError(t *testing.T) {

shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Get(r.Context(), actor.TypeAttorney, sharecodedata.HashedFromString("abcdef123456")).
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, nil)

sessionStore := newMockSessionStore(t)
Expand All @@ -230,7 +230,7 @@ func TestPostEnterReferenceNumberOnAttorneyStoreError(t *testing.T) {

shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Get(r.Context(), actor.TypeAttorney, sharecodedata.HashedFromString("abcdef123456")).
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, nil)

attorneyStore := newMockAttorneyStore(t)
Expand Down
28 changes: 14 additions & 14 deletions internal/attorney/attorneypage/mock_ShareCodeStore_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/attorney/attorneypage/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ type OneLoginClient interface {
}

type ShareCodeStore interface {
Get(ctx context.Context, actorType actor.Type, shareCode string) (sharecodedata.Link, error)
Put(ctx context.Context, actorType actor.Type, shareCode string, data sharecodedata.Link) error
Get(ctx context.Context, actorType actor.Type, shareCode sharecodedata.Hashed) (sharecodedata.Link, error)
Put(ctx context.Context, actorType actor.Type, shareCode sharecodedata.Hashed, data sharecodedata.Link) error
Delete(ctx context.Context, shareCode sharecodedata.Link) error
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)
Expand Down Expand Up @@ -42,7 +43,9 @@ func ConfirmDontWantToBeCertificateProviderLoggedOut(tmpl template.Template, sha
}

if r.Method == http.MethodPost {
shareCode, err := shareCodeStore.Get(r.Context(), actor.TypeCertificateProvider, r.URL.Query().Get("referenceNumber"))
code := sharecodedata.HashedFromQuery(r.URL.Query())

shareCode, err := shareCodeStore.Get(r.Context(), actor.TypeCertificateProvider, code)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestGetConfirmDontWantToBeCertificateProviderLoggedOutErrors(t *testing.T)
}

func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) {
r, _ := http.NewRequest(http.MethodPost, "/?referenceNumber=123", nil)
r, _ := http.NewRequest(http.MethodPost, "/?code=da4ec3358a10c9b0872eb877953cc7b07af5f4d75e4c1cb0597cbbf41e5dbe35", nil)
w := httptest.NewRecorder()
ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"})

Expand Down Expand Up @@ -270,7 +270,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) {

shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeCertificateProvider, "123").
Get(r.Context(), actor.TypeCertificateProvider, sharecodedata.HashedFromString("abcdef123456")).
Return(shareCodeData, nil)
shareCodeStore.EXPECT().
Delete(r.Context(), shareCodeData).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)

Expand All @@ -31,7 +32,7 @@ func EnterReferenceNumber(tmpl template.Template, shareCodeStore ShareCodeStore,
data.Errors = data.Form.Validate()

if len(data.Errors) == 0 {
referenceNumber := data.Form.ReferenceNumber
referenceNumber := sharecodedata.HashedFromString(data.Form.ReferenceNumber)

shareCode, err := shareCodeStore.Get(r.Context(), actor.TypeCertificateProvider, referenceNumber)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package certificateproviderpage
import (
"errors"
"net/http"
"net/url"

"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)

Expand All @@ -26,7 +26,7 @@ func EnterReferenceNumberOptOut(tmpl template.Template, shareCodeStore ShareCode
data.Errors = data.Form.Validate()

if data.Errors.None() {
referenceNumber := data.Form.ReferenceNumber
referenceNumber := sharecodedata.HashedFromString(data.Form.ReferenceNumber)

shareCode, err := shareCodeStore.Get(r.Context(), actor.TypeCertificateProvider, referenceNumber)
if err != nil {
Expand All @@ -42,7 +42,7 @@ func EnterReferenceNumberOptOut(tmpl template.Template, shareCodeStore ShareCode
return err
}

return page.PathCertificateProviderConfirmDontWantToBeCertificateProviderLoggedOut.RedirectQuery(w, r, appData, url.Values{"referenceNumber": {referenceNumber}})
return page.PathCertificateProviderConfirmDontWantToBeCertificateProviderLoggedOut.RedirectQuery(w, r, appData, referenceNumber.Query())
}
}

Expand Down
Loading

0 comments on commit baf813b

Please sign in to comment.