Skip to content

Commit

Permalink
linting done
Browse files Browse the repository at this point in the history
  • Loading branch information
himran92 committed Nov 28, 2024
1 parent 91cd02b commit 33fc312
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion saml/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ var (
ErrInvalidAudience = errors.New("invalid audience")
ErrMissingSubject = errors.New("subject missing")
ErrMissingAttributeStmt = errors.New("attribute statement missing")
ErrInvalidSignature = errors.New("invalid signature")
ErrInvalidSignature = errors.New("invalid signature")
)
10 changes: 4 additions & 6 deletions saml/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func (sp *ServiceProvider) ParseResponse(
// This will validate the response and all assertions.
response, err := ip.ValidateEncodedResponse(samlResp)


switch {
case err != nil:
return nil, fmt.Errorf("%s: unable to validate encoded response: %w", op, err)
Expand Down Expand Up @@ -257,11 +256,10 @@ func parsePEMCertificate(cert []byte) (*x509.Certificate, error) {
return x509.ParseCertificate(block.Bytes)
}

func validateSignature(response *types.Response, op string) (error) {

func validateSignature(response *types.Response, op string) error {
// validate child attr assertions
for _, assert := range response.Assertions {
if !assert.SignatureValidated{
if !assert.SignatureValidated {
// note: at one time func ip.ValidateEncodedResponse(...) above allows all signed or all unsigned
// assertions, and will give error if there are both. We are still looping on all assertions instead of
// retrieving value for one assertion, so we do not depend on dependency implementation.
Expand All @@ -270,8 +268,8 @@ func validateSignature(response *types.Response, op string) (error) {
}

// validate root response attr
if !response.SignatureValidated{
if !response.SignatureValidated {
return fmt.Errorf("%s: %w", op, ErrInvalidSignature)
}
return nil
}
}
30 changes: 15 additions & 15 deletions saml/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,27 @@ func TestServiceProvider_ParseResponse(t *testing.T) {
requestID: testRequestId,
},
{
name: "missing signature",
sp: testSp,
samlResp: base64.StdEncoding.EncodeToString([]byte(tp.SamlResponse(t))),
opts: []saml.Option{},
requestID: testRequestId,
name: "missing signature",
sp: testSp,
samlResp: base64.StdEncoding.EncodeToString([]byte(tp.SamlResponse(t))),
opts: []saml.Option{},
requestID: testRequestId,
wantErrContains: "response and/or assertions must be signed",
},
{
name: "error-invalid-signature",
sp: testSp,
samlResp: base64.StdEncoding.EncodeToString([]byte(tp.SamlResponse(t, testprovider.WithJustResponseElemSigned()))),
opts: []saml.Option{},
requestID: testRequestId,
name: "error-invalid-signature",
sp: testSp,
samlResp: base64.StdEncoding.EncodeToString([]byte(tp.SamlResponse(t, testprovider.WithJustResponseElemSigned()))),
opts: []saml.Option{},
requestID: testRequestId,
wantErrContains: "invalid signature",
},
{
name: "error-invalid-signature",
sp: testSp,
samlResp: base64.StdEncoding.EncodeToString([]byte(tp.SamlResponse(t, testprovider.WithJustResponseElemSigned()))),
opts: []saml.Option{},
requestID: testRequestId,
name: "error-invalid-signature",
sp: testSp,
samlResp: base64.StdEncoding.EncodeToString([]byte(tp.SamlResponse(t, testprovider.WithJustResponseElemSigned()))),
opts: []saml.Option{},
requestID: testRequestId,
wantErrContains: "invalid signature",
},
{
Expand Down
10 changes: 5 additions & 5 deletions saml/test/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ func (p *TestProvider) parseRequestPost(request string) *core.AuthnRequest {
}

type responseOptions struct {
signResponseElem bool
signResponseElem bool
signAssertionElem bool
expired bool
expired bool
}

type ResponseOption func(*responseOptions)
Expand Down Expand Up @@ -558,11 +558,11 @@ func (p *TestProvider) SamlResponse(t *testing.T, opts ...ResponseOption) string
err = doc.ReadFromBytes(resp)
r.NoError(err)

if opt.signResponseElem || opt.signAssertionElem {
if opt.signResponseElem || opt.signAssertionElem {
signCtx := dsig.NewDefaultSigningContext(p.keystore)

// sign child attr assertions
if opt.signAssertionElem{
if opt.signAssertionElem {
responseEl := doc.SelectElement("Response")
for _, assert := range responseEl.FindElements("Assertion") {
signedAssert, err := signCtx.SignEnveloped(assert)
Expand All @@ -575,7 +575,7 @@ func (p *TestProvider) SamlResponse(t *testing.T, opts ...ResponseOption) string
}

// sign root attr response
if opt.signResponseElem{
if opt.signResponseElem {
signed, err := signCtx.SignEnveloped(doc.Root())
r.NoError(err)
doc.SetRoot(signed)
Expand Down

0 comments on commit 33fc312

Please sign in to comment.