From 5ea047610746698e62b9c938e4c0eb2240a4f1b7 Mon Sep 17 00:00:00 2001 From: AshersLab Date: Fri, 6 Aug 2021 22:30:48 +1000 Subject: [PATCH] fixes and casing --- internal/hydra/consent.go | 10 +++++----- internal/hydra/consent_test.go | 4 ++-- internal/hydra/hydra.go | 8 ++++---- internal/hydra/login.go | 10 +++++----- internal/hydra/login_test.go | 4 ++-- internal/hydra/logout.go | 10 +++++----- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/internal/hydra/consent.go b/internal/hydra/consent.go index f28c251..1ebe85e 100644 --- a/internal/hydra/consent.go +++ b/internal/hydra/consent.go @@ -14,18 +14,18 @@ import ( // ConsentReqDoer fetches information on the OAuth2 request and then accept or reject the requested authentication process. type ConsentReqDoer struct { hydraURL string - fakeTlsTermination bool + fakeTLSTermination bool rememberFor int } // NewConsentReqDoer creates a ConsentRequest. -func NewConsentReqDoer(hydraURL string, fakeTlsTermination bool, rememberFor int) *ConsentReqDoer { - return &ConsentReqDoer{hydraURL: hydraURL, fakeTlsTermination: fakeTlsTermination, rememberFor: rememberFor} +func NewConsentReqDoer(hydraURL string, fakeTLSTermination bool, rememberFor int) *ConsentReqDoer { + return &ConsentReqDoer{hydraURL: hydraURL, fakeTLSTermination: fakeTLSTermination, rememberFor: rememberFor} } // InitiateRequest fetches information on the OAuth2 request. func (crd *ConsentReqDoer) InitiateRequest(challenge string) (*ReqInfo, error) { - ri, err := initiateRequest(consent, crd.hydraURL, crd.fakeTlsTermination, challenge) + ri, err := initiateRequest(consent, crd.hydraURL, crd.fakeTLSTermination, challenge) return ri, errors.Wrap(err, "failed to initiate consent request") } @@ -47,6 +47,6 @@ func (crd *ConsentReqDoer) AcceptConsentRequest(challenge string, remember bool, IDToken: idToken, }, } - redirectURI, err := acceptRequest(consent, crd.hydraURL, crd.fakeTlsTermination, challenge, data) + redirectURI, err := acceptRequest(consent, crd.hydraURL, crd.fakeTLSTermination, challenge, data) return redirectURI, errors.Wrap(err, "failed to accept consent request") } diff --git a/internal/hydra/consent_test.go b/internal/hydra/consent_test.go index 85e43ab..13b7acd 100644 --- a/internal/hydra/consent_test.go +++ b/internal/hydra/consent_test.go @@ -55,7 +55,7 @@ func TestInitiateConsentRequest(t *testing.T) { h := &testInitiateConsentHandler{reqInfo: tc.reqInfo, status: tc.status} srv := httptest.NewServer(h) defer srv.Close() - ldr := hydra.NewConsentReqDoer(srv.URL, tc.rememberFor) + ldr := hydra.NewConsentReqDoer(srv.URL, false, tc.rememberFor) reqInfo, err := ldr.InitiateRequest(tc.challenge) @@ -149,7 +149,7 @@ func TestAcceptConsentRequest(t *testing.T) { h := &testAcceptConsentHandler{challenge: tc.challenge, status: tc.status, redirect: tc.redirect} srv := httptest.NewServer(h) defer srv.Close() - ldr := hydra.NewConsentReqDoer(srv.URL, tc.rememberFor) + ldr := hydra.NewConsentReqDoer(srv.URL, false, tc.rememberFor) var grantScope []string for _, v := range tc.grantScope { diff --git a/internal/hydra/hydra.go b/internal/hydra/hydra.go index a75186c..8a6a826 100644 --- a/internal/hydra/hydra.go +++ b/internal/hydra/hydra.go @@ -44,7 +44,7 @@ type ReqInfo struct { Subject string `json:"subject"` } -func initiateRequest(typ reqType, hydraURL string, fakeTlsTermination bool, challenge string) (*ReqInfo, error) { +func initiateRequest(typ reqType, hydraURL string, fakeTLSTermination bool, challenge string) (*ReqInfo, error) { if challenge == "" { return nil, ErrChallengeMissed } @@ -62,7 +62,7 @@ func initiateRequest(typ reqType, hydraURL string, fakeTlsTermination bool, chal if err != nil { return nil, err } - if fakeTlsTermination { + if fakeTLSTermination { req.Header.Add("X-Forwarded-Proto", "https") } @@ -85,7 +85,7 @@ func initiateRequest(typ reqType, hydraURL string, fakeTlsTermination bool, chal return &ri, nil } -func acceptRequest(typ reqType, hydraURL string, fakeTlsTermination bool, challenge string, data interface{}) (string, error) { +func acceptRequest(typ reqType, hydraURL string, fakeTLSTermination bool, challenge string, data interface{}) (string, error) { if challenge == "" { return "", ErrChallengeMissed } @@ -110,7 +110,7 @@ func acceptRequest(typ reqType, hydraURL string, fakeTlsTermination bool, challe if err != nil { return "", err } - if fakeTlsTermination { + if fakeTLSTermination { r.Header.Add("X-Forwarded-Proto", "https") } diff --git a/internal/hydra/login.go b/internal/hydra/login.go index ab3a78b..f2efa9c 100644 --- a/internal/hydra/login.go +++ b/internal/hydra/login.go @@ -14,18 +14,18 @@ import ( // LoginReqDoer fetches information on the OAuth2 request and then accept or reject the requested authentication process. type LoginReqDoer struct { hydraURL string - fakeTlsTermination bool + fakeTLSTermination bool rememberFor int } // NewLoginReqDoer creates a LoginRequest. -func NewLoginReqDoer(hydraURL string, fakeTlsTermination bool, rememberFor int) *LoginReqDoer { - return &LoginReqDoer{hydraURL: hydraURL, fakeTlsTermination: fakeTlsTermination, rememberFor: rememberFor} +func NewLoginReqDoer(hydraURL string, fakeTLSTermination bool, rememberFor int) *LoginReqDoer { + return &LoginReqDoer{hydraURL: hydraURL, fakeTLSTermination: fakeTLSTermination, rememberFor: rememberFor} } // InitiateRequest fetches information on the OAuth2 request. func (lrd *LoginReqDoer) InitiateRequest(challenge string) (*ReqInfo, error) { - ri, err := initiateRequest(login, lrd.hydraURL, lrd.fakeTlsTermination, challenge) + ri, err := initiateRequest(login, lrd.hydraURL, lrd.fakeTLSTermination, challenge) return ri, errors.Wrap(err, "failed to initiate login request") } @@ -40,6 +40,6 @@ func (lrd *LoginReqDoer) AcceptLoginRequest(challenge string, remember bool, sub RememberFor: lrd.rememberFor, Subject: subject, } - redirectURI, err := acceptRequest(login, lrd.hydraURL, lrd.fakeTlsTermination, challenge, data) + redirectURI, err := acceptRequest(login, lrd.hydraURL, lrd.fakeTLSTermination, challenge, data) return redirectURI, errors.Wrap(err, "failed to accept login request") } diff --git a/internal/hydra/login_test.go b/internal/hydra/login_test.go index 01a9821..f5a75ff 100644 --- a/internal/hydra/login_test.go +++ b/internal/hydra/login_test.go @@ -60,7 +60,7 @@ func TestInitiateLoginRequest(t *testing.T) { h := &testInitiateLoginHandler{reqInfo: tc.reqInfo, status: tc.status} srv := httptest.NewServer(h) defer srv.Close() - ldr := hydra.NewLoginReqDoer(srv.URL, 0) + ldr := hydra.NewLoginReqDoer(srv.URL, false, 0) reqInfo, err := ldr.InitiateRequest(tc.challenge) @@ -160,7 +160,7 @@ func TestAcceptLoginRequest(t *testing.T) { h := &testAcceptLoginHandler{challenge: tc.challenge, status: tc.status, redirect: tc.redirect} srv := httptest.NewServer(h) defer srv.Close() - ldr := hydra.NewLoginReqDoer(srv.URL, tc.rememberFor) + ldr := hydra.NewLoginReqDoer(srv.URL, false, tc.rememberFor) redirect, err := ldr.AcceptLoginRequest(tc.challenge, tc.remember, tc.subject) diff --git a/internal/hydra/logout.go b/internal/hydra/logout.go index 5458482..c901a88 100644 --- a/internal/hydra/logout.go +++ b/internal/hydra/logout.go @@ -14,22 +14,22 @@ import ( // LogoutReqDoer fetches information on the OAuth2 request and then accepts or rejects the requested logout process. type LogoutReqDoer struct { hydraURL string - fakeTlsTermination bool + fakeTLSTermination bool } // NewLogoutReqDoer creates a LogoutRequest. -func NewLogoutReqDoer(hydraURL string, fakeTlsTermination bool) *LogoutReqDoer { - return &LogoutReqDoer{hydraURL: hydraURL, fakeTlsTermination: fakeTlsTermination} +func NewLogoutReqDoer(hydraURL string, fakeTLSTermination bool) *LogoutReqDoer { + return &LogoutReqDoer{hydraURL: hydraURL, fakeTLSTermination: fakeTLSTermination} } // InitiateRequest fetches information on the OAuth2 request. func (lrd *LogoutReqDoer) InitiateRequest(challenge string) (*ReqInfo, error) { - ri, err := initiateRequest(logout, lrd.hydraURL, lrd.fakeTlsTermination, challenge) + ri, err := initiateRequest(logout, lrd.hydraURL, lrd.fakeTLSTermination, challenge) return ri, errors.Wrap(err, "failed to initiate logout request") } // AcceptLogoutRequest accepts the requested logout process, and returns redirect URI. func (lrd *LogoutReqDoer) AcceptLogoutRequest(challenge string) (string, error) { - redirectURI, err := acceptRequest(logout, lrd.hydraURL, lrd.fakeTlsTermination, challenge, nil) + redirectURI, err := acceptRequest(logout, lrd.hydraURL, lrd.fakeTLSTermination, challenge, nil) return redirectURI, errors.Wrap(err, "failed to accept logout request") }