Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Update golangci lint #45

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.54.2
version: v1.60.2
9 changes: 8 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,15 @@ linters-settings:
- unreachable
- unsafeptr
- unusedresult

issues:
exclude-use-default: false
exclude:
- G104 # 'Errors unhandled. (gosec)

exclude-rules:
- path: _test\.go
linters:
- errcheck
- path: example/
linters:
- errcheck
161 changes: 80 additions & 81 deletions identity_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ func NewIdentityProviderTest(t *testing.T, opts ...idpTestOpts) *IdentityProvide
MetadataURL: mustParseURL("https://idp.example.com/saml/metadata"),
SSOURL: mustParseURL("https://idp.example.com/saml/sso"),
ServiceProviderProvider: &mockServiceProviderProvider{
GetServiceProviderFunc: func(r *http.Request, serviceProviderID string) (*EntityDescriptor, error) {
GetServiceProviderFunc: func(_ *http.Request, serviceProviderID string) (*EntityDescriptor, error) {
if serviceProviderID == test.SP.MetadataURL.String() {
return test.SP.Metadata(), nil
}
return nil, os.ErrNotExist
},
},
SessionProvider: &mockSessionProvider{
GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
GetSessionFunc: func(_ http.ResponseWriter, _ *http.Request, _ *IdpAuthnRequest) *Session {
return nil
},
},
Expand Down Expand Up @@ -244,7 +244,7 @@ func TestIDPHTTPCanHandleMetadataRequest(t *testing.T) {
func TestIDPCanHandleRequestWithNewSession(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
test.IDP.SessionProvider = &mockSessionProvider{
GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
GetSessionFunc: func(w http.ResponseWriter, _ *http.Request, req *IdpAuthnRequest) *Session {
fmt.Fprintf(w, "RelayState: %s\nSAMLRequest: %s",
req.RelayState, req.RequestBuffer)
return nil
Expand All @@ -270,7 +270,7 @@ func TestIDPCanHandleRequestWithNewSession(t *testing.T) {
func TestIDPCanHandleRequestWithExistingSession(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
test.IDP.SessionProvider = &mockSessionProvider{
GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
GetSessionFunc: func(_ http.ResponseWriter, _ *http.Request, _ *IdpAuthnRequest) *Session {
return &Session{
ID: "f00df00df00d",
UserName: "alice",
Expand All @@ -295,7 +295,7 @@ func TestIDPCanHandleRequestWithExistingSession(t *testing.T) {
func TestIDPCanHandlePostRequestWithExistingSession(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
test.IDP.SessionProvider = &mockSessionProvider{
GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
GetSessionFunc: func(_ http.ResponseWriter, _ *http.Request, _ *IdpAuthnRequest) *Session {
return &Session{
ID: "f00df00df00d",
UserName: "alice",
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestIDPCanHandlePostRequestWithExistingSession(t *testing.T) {
func TestIDPRejectsInvalidRequest(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
test.IDP.SessionProvider = &mockSessionProvider{
GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
GetSessionFunc: func(_ http.ResponseWriter, _ *http.Request, _ *IdpAuthnRequest) *Session {
panic("not reached")
},
}
Expand Down Expand Up @@ -487,7 +487,6 @@ func TestIDPCanValidate(t *testing.T) {
"</AuthnRequest>"),
}
assert.Check(t, is.Error(req.Validate(), "cannot find assertion consumer service: file does not exist"))

}

func TestIDPMakeAssertion(t *testing.T) {
Expand Down Expand Up @@ -594,83 +593,82 @@ func TestIDPMakeAssertion(t *testing.T) {
})
assert.Check(t, err)

expectedAttributes :=
[]Attribute{
{
FriendlyName: "uid",
Name: "urn:oid:0.9.2342.19200300.100.1.1",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "alice",
},
expectedAttributes := []Attribute{
{
FriendlyName: "uid",
Name: "urn:oid:0.9.2342.19200300.100.1.1",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "alice",
},
},
{
FriendlyName: "eduPersonPrincipalName",
Name: "urn:oid:1.3.6.1.4.1.5923.1.1.1.6",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "[email protected]",
},
},
{
FriendlyName: "eduPersonPrincipalName",
Name: "urn:oid:1.3.6.1.4.1.5923.1.1.1.6",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "[email protected]",
},
},
{
FriendlyName: "sn",
Name: "urn:oid:2.5.4.4",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "Smith",
},
},
{
FriendlyName: "sn",
Name: "urn:oid:2.5.4.4",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "Smith",
},
},
{
FriendlyName: "givenName",
Name: "urn:oid:2.5.4.42",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "Alice",
},
},
{
FriendlyName: "givenName",
Name: "urn:oid:2.5.4.42",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "Alice",
},
},
{
FriendlyName: "cn",
Name: "urn:oid:2.5.4.3",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "Alice Smith",
},
},
{
FriendlyName: "cn",
Name: "urn:oid:2.5.4.3",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "Alice Smith",
},
},
{
FriendlyName: "eduPersonAffiliation",
Name: "urn:oid:1.3.6.1.4.1.5923.1.1.1.1",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "Users",
},
{
Type: "xs:string",
Value: "Administrators",
},
{
Type: "xs:string",
Value: "♀",
},
},
{
FriendlyName: "eduPersonAffiliation",
Name: "urn:oid:1.3.6.1.4.1.5923.1.1.1.1",
NameFormat: "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
Values: []AttributeValue{
{
Type: "xs:string",
Value: "Users",
},
{
Type: "xs:string",
Value: "Administrators",
},
{
Type: "xs:string",
Value: "♀",
},
},
}
},
}
assert.Check(t, is.DeepEqual(expectedAttributes, req.Assertion.AttributeStatements[0].Attributes))
}

Expand Down Expand Up @@ -801,7 +799,7 @@ func TestIDPWriteResponse(t *testing.T) {
func TestIDPIDPInitiatedNewSession(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
test.IDP.SessionProvider = &mockSessionProvider{
GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
GetSessionFunc: func(w http.ResponseWriter, _ *http.Request, req *IdpAuthnRequest) *Session {
fmt.Fprintf(w, "RelayState: %s", req.RelayState)
return nil
},
Expand All @@ -817,7 +815,7 @@ func TestIDPIDPInitiatedNewSession(t *testing.T) {
func TestIDPIDPInitiatedExistingSession(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
test.IDP.SessionProvider = &mockSessionProvider{
GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
GetSessionFunc: func(_ http.ResponseWriter, _ *http.Request, _ *IdpAuthnRequest) *Session {
return &Session{
ID: "f00df00df00d",
UserName: "alice",
Expand All @@ -835,7 +833,7 @@ func TestIDPIDPInitiatedExistingSession(t *testing.T) {
func TestIDPIDPInitiatedBadServiceProvider(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
test.IDP.SessionProvider = &mockSessionProvider{
GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
GetSessionFunc: func(_ http.ResponseWriter, _ *http.Request, _ *IdpAuthnRequest) *Session {
return &Session{
ID: "f00df00df00d",
UserName: "alice",
Expand All @@ -852,7 +850,7 @@ func TestIDPIDPInitiatedBadServiceProvider(t *testing.T) {
func TestIDPCanHandleUnencryptedResponse(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
test.IDP.SessionProvider = &mockSessionProvider{
GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
GetSessionFunc: func(_ http.ResponseWriter, _ *http.Request, _ *IdpAuthnRequest) *Session {
return &Session{ID: "f00df00df00d", UserName: "alice"}
},
}
Expand All @@ -863,7 +861,7 @@ func TestIDPCanHandleUnencryptedResponse(t *testing.T) {
&metadata)
assert.Check(t, err)
test.IDP.ServiceProviderProvider = &mockServiceProviderProvider{
GetServiceProviderFunc: func(r *http.Request, serviceProviderID string) (*EntityDescriptor, error) {
GetServiceProviderFunc: func(_ *http.Request, serviceProviderID string) (*EntityDescriptor, error) {
if serviceProviderID == "https://gitlab.example.com/users/saml/metadata" {
return &metadata, nil
}
Expand Down Expand Up @@ -1023,14 +1021,15 @@ func TestIDPRequestedAttributes(t *testing.T) {
},
},
},
}}}
},
}}
assert.Check(t, is.DeepEqual(expectedAttributes, req.Assertion.AttributeStatements))
}

func TestIDPNoDestination(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
test.IDP.SessionProvider = &mockSessionProvider{
GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
GetSessionFunc: func(_ http.ResponseWriter, _ *http.Request, _ *IdpAuthnRequest) *Session {
return &Session{ID: "f00df00df00d", UserName: "alice"}
},
}
Expand All @@ -1039,7 +1038,7 @@ func TestIDPNoDestination(t *testing.T) {
err := xml.Unmarshal(golden.Get(t, "TestIDPNoDestination_idp_metadata.xml"), &metadata)
assert.Check(t, err)
test.IDP.ServiceProviderProvider = &mockServiceProviderProvider{
GetServiceProviderFunc: func(r *http.Request, serviceProviderID string) (*EntityDescriptor, error) {
GetServiceProviderFunc: func(_ *http.Request, serviceProviderID string) (*EntityDescriptor, error) {
if serviceProviderID == "https://gitlab.example.com/users/saml/metadata" {
return &metadata, nil
}
Expand Down Expand Up @@ -1070,7 +1069,7 @@ func TestIDPNoDestination(t *testing.T) {
func TestIDPRejectDecompressionBomb(t *testing.T) {
test := NewIdentityProviderTest(t)
test.IDP.SessionProvider = &mockSessionProvider{
GetSessionFunc: func(w http.ResponseWriter, r *http.Request, req *IdpAuthnRequest) *Session {
GetSessionFunc: func(w http.ResponseWriter, _ *http.Request, req *IdpAuthnRequest) *Session {
fmt.Fprintf(w, "RelayState: %s\nSAMLRequest: %s",
req.RelayState, req.RequestBuffer)
return nil
Expand Down
Loading
Loading