Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mgyongyosi committed Oct 25, 2023
1 parent 84c2df3 commit a6c0e9b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions identity_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<EntityDescriptor"),
string(w.Body.Bytes()))
w.Body.String())
}

func TestIDPCanHandleRequestWithNewSession(t *testing.T) {
Expand Down
15 changes: 10 additions & 5 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ type IDPSSODescriptor struct {
Attributes []Attribute `xml:"Attribute"`
}

func (m IDPSSODescriptor) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
// MarshalXML implements xml.Marshaler
func (m IDPSSODescriptor) MarshalXML(e *xml.Encoder, _ xml.StartElement) error {
type Alias IDPSSODescriptor
aux := &struct {
ValidUntil RelaxedTime `xml:"validUntil,attr,omitempty"`
Expand Down Expand Up @@ -377,7 +378,8 @@ type SPSSODescriptor struct {
AttributeConsumingServices []AttributeConsumingService `xml:"AttributeConsumingService"`
}

func (m SPSSODescriptor) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
// MarshalXML implements xml.Marshaler
func (m SPSSODescriptor) MarshalXML(e *xml.Encoder, _ xml.StartElement) error {
type Alias SPSSODescriptor
aux := &struct {
ValidUntil RelaxedTime `xml:"validUntil,attr,omitempty"`
Expand Down Expand Up @@ -439,7 +441,8 @@ type AuthnAuthorityDescriptor struct {
NameIDFormats []NameIDFormat `xml:"NameIDFormat"`
}

func (m AuthnAuthorityDescriptor) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
// MarshalXML implements xml.Marshaler
func (m AuthnAuthorityDescriptor) MarshalXML(e *xml.Encoder, _ xml.StartElement) error {
type Alias AuthnAuthorityDescriptor
aux := &struct {
ValidUntil RelaxedTime `xml:"validUntil,attr,omitempty"`
Expand Down Expand Up @@ -482,7 +485,8 @@ type PDPDescriptor struct {
NameIDFormats []NameIDFormat `xml:"NameIDFormat"`
}

func (m PDPDescriptor) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
// MarshalXML implements xml.Marshaler
func (m PDPDescriptor) MarshalXML(e *xml.Encoder, _ xml.StartElement) error {
type Alias PDPDescriptor
aux := &struct {
ValidUntil RelaxedTime `xml:"validUntil,attr,omitempty"`
Expand Down Expand Up @@ -527,7 +531,8 @@ type AttributeAuthorityDescriptor struct {
Attributes []Attribute `xml:"Attribute"`
}

func (m AttributeAuthorityDescriptor) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
// MarshalXML implements xml.Marshaler
func (m AttributeAuthorityDescriptor) MarshalXML(e *xml.Encoder, _ xml.StartElement) error {
type Alias AttributeAuthorityDescriptor
aux := &struct {
ValidUntil RelaxedTime `xml:"validUntil,attr,omitempty"`
Expand Down
7 changes: 2 additions & 5 deletions service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (r *AuthnRequest) Redirect(relayState string, sp *ServiceProvider) (*url.UR

rv, _ := url.Parse(r.Destination)
// We can't depend on Query().set() as order matters for signing
reqString := string(w.Bytes())
reqString := w.String()
query := rv.RawQuery
if len(query) > 0 {
query += "&" + string(samlRequest) + "=" + url.QueryEscape(reqString)
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions service_provider_signed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion service_provider_signed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func TestSigningAndValidation(t *testing.T) {
desc string
relayState string
requestType reqType
wantErr bool
wantRawQuery string
}

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

0 comments on commit a6c0e9b

Please sign in to comment.