Skip to content

Commit

Permalink
update for most recent three go versions
Browse files Browse the repository at this point in the history
  • Loading branch information
crewjam committed Oct 14, 2023
1 parent 34930b2 commit 38d7189
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 492 deletions.
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@v2
with:
version: v1.52.2
version: v1.54.2
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.17.x', '1.18.x', '1.19.x']
go: [ '1.19.x', '1.20.x', '1.21.x']
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
- name: Go version
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
linters:
enable:
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
- errcheck # Inspects source code for security problems [fast: true, auto-fix: false]
- gocritic # The most opinionated Go source code linter [fast: true, auto-fix: false]
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
Expand Down Expand Up @@ -36,6 +35,7 @@ linters:
- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false]
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
- lll # Reports long lines [fast: true, auto-fix: false]
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
linters-settings:
goimports:
local-prefixes: github.com/crewjam/saml
Expand Down
57 changes: 0 additions & 57 deletions identity_provider_go116_test.go

This file was deleted.

59 changes: 0 additions & 59 deletions identity_provider_go117_test.go

This file was deleted.

42 changes: 42 additions & 0 deletions identity_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"encoding/pem"
"encoding/xml"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -1088,3 +1089,44 @@ func TestIDPRejectDecompressionBomb(t *testing.T) {
_, err = NewIdpAuthnRequest(&test.IDP, r)
assert.Error(t, err, "cannot decompress request: flate: uncompress limit exceeded (10485760 bytes)")
}

func TestIDPHTTPCanHandleSSORequest(t *testing.T) {
test := NewIdentityProviderTest(t, applyKey)
w := httptest.NewRecorder()

const validRequest = `lJJBayoxFIX%2FypC9JhnU5wszAz7lgWCLaNtFd5fMbQ1MkmnunVb%2FfUfbUqEgdhs%2BTr5zkmLW8S5s8KVD4mzvm0Cl6FIwEciRCeCRDFuznd2sTD5Upk2Ro42NyGZEmNjFMI%2BBOo9pi%2BnVWbzfrEqxY27JSEntEPfg2waHNnpJ4JtcgiWRLfoLXYBjwDfu6p%2B8JIoiWy5K4eqBUipXIzVRUwXKKtRK53qkJ3qqQVuNPUjU4TIQQ%2BBS5EqPBzofKH2ntBn%2FMervo8jWnyX%2BuVC78FwKkT1gopNKX1JUxSklXTMIfM0gsv8xeeDL%2BPGk7%2FF0Qg0GdnwQ1cW5PDLUwFDID6uquO1Dlot1bJw9%2FPLRmia%2BzRMCYyk4dSiq6205QSDXOxfy3KAq5Pkvqt4DAAD%2F%2Fw%3D%3D`

r, _ := http.NewRequest("GET", "https://idp.example.com/saml/sso?RelayState=ThisIsTheRelayState&"+
"SAMLRequest="+validRequest, nil)
test.IDP.Handler().ServeHTTP(w, r)
assert.Check(t, is.Equal(http.StatusOK, w.Code))

// rejects requests that are invalid
w = httptest.NewRecorder()
r, _ = http.NewRequest("GET", "https://idp.example.com/saml/sso?RelayState=ThisIsTheRelayState&"+
"SAMLRequest=PEF1dGhuUmVxdWVzdA%3D%3D", nil)
test.IDP.Handler().ServeHTTP(w, r)
assert.Check(t, is.Equal(http.StatusBadRequest, w.Code))

// rejects requests that contain malformed XML
{
a, _ := url.QueryUnescape(validRequest)
b, _ := base64.StdEncoding.DecodeString(a)
c, _ := ioutil.ReadAll(flate.NewReader(bytes.NewReader(b)))
d := bytes.Replace(c, []byte("<AuthnRequest"), []byte("<AuthnRequest ::foo=\"bar\">]]"), 1)
f := bytes.Buffer{}
e, _ := flate.NewWriter(&f, flate.DefaultCompression)
_, err := e.Write(d)
assert.Check(t, err)
err = e.Close()
assert.Check(t, err)
g := base64.StdEncoding.EncodeToString(f.Bytes())
invalidRequest := url.QueryEscape(g)

w = httptest.NewRecorder()
r, _ = http.NewRequest("GET", "https://idp.example.com/saml/sso?RelayState=ThisIsTheRelayState&"+
"SAMLRequest="+invalidRequest, nil)
test.IDP.Handler().ServeHTTP(w, r)
assert.Check(t, is.Equal(http.StatusBadRequest, w.Code))
}
}
26 changes: 0 additions & 26 deletions samlidp/util_go116_test.go

This file was deleted.

5 changes: 2 additions & 3 deletions samlidp/util_go117_test.go → samlidp/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import (
"testing"

"gotest.tools/assert"
is "gotest.tools/assert/cmp"
)

func TestGetSPMetadata(t *testing.T) {
good := "" +
"<EntityDescriptor xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\" ::attr=\"foo\" validUntil=\"2013-03-10T00:32:19.104Z\" cacheDuration=\"PT1H\" entityID=\"http://localhost:5000/e087a985171710fb9fb30f30f41384f9/saml2/metadata/\">\n" +
"<EntityDescriptor xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\" validUntil=\"2013-03-10T00:32:19.104Z\" cacheDuration=\"PT1H\" entityID=\"http://localhost:5000/e087a985171710fb9fb30f30f41384f9/saml2/metadata/\">\n" +
"</EntityDescriptor>"
_, err := getSPMetadata(strings.NewReader(good))
assert.Check(t, err)
Expand All @@ -22,5 +21,5 @@ func TestGetSPMetadata(t *testing.T) {
"<EntityDescriptor xmlns=\"urn:oasis:names:tc:SAML:2.0:metadata\" ::attr=\"foo\" validUntil=\"2013-03-10T00:32:19.104Z\" cacheDuration=\"PT1H\" entityID=\"http://localhost:5000/e087a985171710fb9fb30f30f41384f9/saml2/metadata/\">]]>\n" +
"</EntityDescriptor>"
_, err = getSPMetadata(strings.NewReader(bad))
assert.Check(t, is.Error(err, "XML syntax error on line 1: unescaped ]]> not in CDATA section"))
assert.Check(t, err != nil)
}
34 changes: 0 additions & 34 deletions samlsp/fetch_metadata_go116_test.go

This file was deleted.

35 changes: 0 additions & 35 deletions samlsp/fetch_metadata_go117_test.go

This file was deleted.

19 changes: 19 additions & 0 deletions samlsp/fetch_metadata_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package samlsp

import (
"bytes"
"context"
"fmt"
"net/http"
Expand All @@ -27,3 +28,21 @@ func TestFetchMetadata(t *testing.T) {
assert.Check(t, err)
assert.Check(t, is.Equal("https://idp.testshib.org/idp/shibboleth", md.EntityID))
}

func TestFetchMetadataRejectsInvalid(t *testing.T) {
test := NewMiddlewareTest(t)
test.IDPMetadata = bytes.ReplaceAll(test.IDPMetadata,
[]byte("<EntityDescriptor "), []byte("<EntityDescriptor ::foo=\"bar\">]]"))

testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Check(t, is.Equal("/metadata", r.URL.String()))
_, err := w.Write(test.IDPMetadata)
assert.Check(t, err)
}))

fmt.Println(testServer.URL + "/metadata")
u, _ := url.Parse(testServer.URL + "/metadata")
md, err := FetchMetadata(context.Background(), testServer.Client(), *u)
assert.Check(t, err != nil)
assert.Check(t, is.Nil(md))
}
2 changes: 1 addition & 1 deletion schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ const (
StatusRequestUnsupported = "urn:oasis:names:tc:SAML:2.0:status:RequestUnsupported"

// StatusRequestVersionDeprecated means the SAML responder cannot process any requests with the protocol version specified in the request.
StatusRequestVersionDeprecated = "urn:oasis:names:tc:SAML:2.0:status:RequestVersionDeprecated"
StatusRequestVersionDeprecated = "urn:oasis:names:tc:SAML:2.0:status:RequestVersionDeprecated" //nolint:gosec

// StatusRequestVersionTooHigh means the SAML responder cannot process the request because the protocol version specified in the request message is a major upgrade from the highest protocol version supported by the responder.
StatusRequestVersionTooHigh = "urn:oasis:names:tc:SAML:2.0:status:RequestVersionTooHigh"
Expand Down
Loading

0 comments on commit 38d7189

Please sign in to comment.