From a6c0e9b86a4c064fa5a593a0575d8656d533e13e Mon Sep 17 00:00:00 2001 From: Mihaly Gyongyosi Date: Wed, 25 Oct 2023 16:38:28 +0200 Subject: [PATCH] Fix linting errors --- identity_provider_test.go | 4 ++-- metadata.go | 15 ++++++++++----- service_provider.go | 7 ++----- service_provider_signed.go | 9 +++++---- service_provider_signed_test.go | 5 ++++- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/identity_provider_test.go b/identity_provider_test.go index 1d068268..b7c711cd 100644 --- a/identity_provider_test.go +++ b/identity_provider_test.go @@ -236,9 +236,9 @@ func TestIDPHTTPCanHandleMetadataRequest(t *testing.T) { test.IDP.Handler().ServeHTTP(w, r) assert.Check(t, is.Equal(http.StatusOK, w.Code)) assert.Check(t, is.Equal("application/samlmetadata+xml", w.Header().Get("Content-type"))) - body := string(w.Body.Bytes()) + body := w.Body.String() assert.Check(t, strings.HasPrefix(body, " 0 { query += "&" + string(samlRequest) + "=" + url.QueryEscape(reqString) @@ -1574,11 +1574,8 @@ func (sp *ServiceProvider) ValidateLogoutResponseRedirect(query url.Values) erro retErr.PrivateErr = err return retErr } - if err := sp.validateLogoutResponse(&resp); err != nil { - return err - } - return nil + return sp.validateLogoutResponse(&resp) } // validateLogoutResponse validates the LogoutResponse fields. Returns a nil error if the LogoutResponse is valid. diff --git a/service_provider_signed.go b/service_provider_signed.go index d8b02f06..0514746a 100644 --- a/service_provider_signed.go +++ b/service_provider_signed.go @@ -72,12 +72,13 @@ func (sp *ServiceProvider) validateQuerySig(query url.Values) error { } respType := "" - if query.Get("SAMLResponse") != "" { + switch { + case query.Get("SAMLResponse") != "": respType = "SAMLResponse" - } else if query.Get("SAMLRequest") != "" { + case query.Get("SAMLRequest") != "": respType = "SAMLRequest" - } else { - return fmt.Errorf("No SAMLResponse or SAMLRequest found in query") + default: + return fmt.Errorf("no SAMLResponse or SAMLRequest found in query") } // Encode Query as standard demands. diff --git a/service_provider_signed_test.go b/service_provider_signed_test.go index a45b8cbd..0ecc9267 100644 --- a/service_provider_signed_test.go +++ b/service_provider_signed_test.go @@ -19,7 +19,6 @@ func TestSigningAndValidation(t *testing.T) { desc string relayState string requestType reqType - wantErr bool wantRawQuery string } @@ -54,6 +53,8 @@ func TestSigningAndValidation(t *testing.T) { } err := xml.Unmarshal(idpMetadata, &s.IDPMetadata) + assert.NilError(t, err) + idpCert, err := s.getIDPSigningCerts() assert.Check(t, err == nil) @@ -102,6 +103,8 @@ func TestInvalidSignatureAlgorithm(t *testing.T) { } err := xml.Unmarshal(idpMetadata, &s.IDPMetadata) + assert.NilError(t, err) + idpCert, err := s.getIDPSigningCerts() assert.Check(t, err == nil)