Skip to content

Commit 193e551

Browse files
authored
update for most recent three go versions (#537)
1 parent 34930b2 commit 193e551

26 files changed

+218
-534
lines changed

.github/workflows/lint.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ on:
88

99
jobs:
1010
golangci:
11-
name: Run golangci-lint
1211
runs-on: ubuntu-latest
1312
steps:
1413
- uses: actions/checkout@v2
1514
- name: golangci-lint
16-
uses: golangci/golangci-lint-action@v2
15+
uses: golangci/golangci-lint-action@v3
1716
with:
18-
version: v1.52.2
17+
version: v1.54.2

.github/workflows/test.yml

+4-11
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,13 @@ on:
77
branches: [ 'main' ]
88
jobs:
99
tests:
10-
name: Run tests
1110
runs-on: ubuntu-latest
1211
strategy:
1312
matrix:
14-
go: [ '1.17.x', '1.18.x', '1.19.x']
13+
go: [ '1.19.x', '1.20.x', '1.21.x']
1514
steps:
16-
- name: Check out code into the Go module directory
17-
uses: actions/checkout@v2
18-
- name: Set up Go ${{ matrix.go }}
19-
uses: actions/setup-go@v2
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-go@v4
2017
with:
2118
go-version: ${{ matrix.go }}
22-
- name: Go version
23-
run: go version
24-
- name: Run Go tests
25-
run: |
26-
go test -v ./...
19+
- run: go test -v ./...

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
linters:
99
enable:
1010
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
11-
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
1211
- errcheck # Inspects source code for security problems [fast: true, auto-fix: false]
1312
- gocritic # The most opinionated Go source code linter [fast: true, auto-fix: false]
1413
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
@@ -36,6 +35,7 @@ linters:
3635
- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false]
3736
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
3837
- lll # Reports long lines [fast: true, auto-fix: false]
38+
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
3939
linters-settings:
4040
goimports:
4141
local-prefixes: github.com/crewjam/saml

go.mod

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/crewjam/saml
22

3-
go 1.16
3+
go 1.19
44

55
require (
66
github.com/beevik/etree v1.1.0
@@ -10,10 +10,19 @@ require (
1010
github.com/google/go-cmp v0.5.9
1111
github.com/kr/pretty v0.3.1
1212
github.com/mattermost/xml-roundtrip-validator v0.1.0
13-
github.com/pkg/errors v0.9.1 // indirect
1413
github.com/russellhaering/goxmldsig v1.3.0
1514
github.com/stretchr/testify v1.8.1
1615
github.com/zenazn/goji v1.0.1
1716
golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed
1817
gotest.tools v2.2.0+incompatible
1918
)
19+
20+
require (
21+
github.com/davecgh/go-spew v1.1.1 // indirect
22+
github.com/jonboulle/clockwork v0.2.2 // indirect
23+
github.com/kr/text v0.2.0 // indirect
24+
github.com/pkg/errors v0.9.1 // indirect
25+
github.com/pmezard/go-difflib v1.0.0 // indirect
26+
github.com/rogpeppe/go-internal v1.9.0 // indirect
27+
gopkg.in/yaml.v3 v3.0.1 // indirect
28+
)

go.sum

-7
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ github.com/zenazn/goji v1.0.1 h1:4lbD8Mx2h7IvloP7r2C0D6ltZP6Ufip8Hn0wmSK5LR8=
5050
github.com/zenazn/goji v1.0.1/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
5151
golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed h1:YoWVYYAfvQ4ddHv3OKmIvX7NCAhFGTj62VP2l2kfBbA=
5252
golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
53-
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
54-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
55-
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
56-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
57-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
58-
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
59-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
6053
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6154
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6255
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=

identity_provider.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/xml"
1010
"fmt"
1111
"io"
12-
"io/ioutil"
1312
"net/http"
1413
"net/url"
1514
"os"
@@ -366,7 +365,7 @@ func NewIdpAuthnRequest(idp *IdentityProvider, r *http.Request) (*IdpAuthnReques
366365
if err != nil {
367366
return nil, fmt.Errorf("cannot decode request: %s", err)
368367
}
369-
req.RequestBuffer, err = ioutil.ReadAll(newSaferFlateReader(bytes.NewReader(compressedRequest)))
368+
req.RequestBuffer, err = io.ReadAll(newSaferFlateReader(bytes.NewReader(compressedRequest)))
370369
if err != nil {
371370
return nil, fmt.Errorf("cannot decompress request: %s", err)
372371
}

identity_provider_go116_test.go

-57
This file was deleted.

identity_provider_go117_test.go

-59
This file was deleted.

identity_provider_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/pem"
1111
"encoding/xml"
1212
"fmt"
13+
"io"
1314
"math/rand"
1415
"net/http"
1516
"net/http/httptest"
@@ -1088,3 +1089,44 @@ func TestIDPRejectDecompressionBomb(t *testing.T) {
10881089
_, err = NewIdpAuthnRequest(&test.IDP, r)
10891090
assert.Error(t, err, "cannot decompress request: flate: uncompress limit exceeded (10485760 bytes)")
10901091
}
1092+
1093+
func TestIDPHTTPCanHandleSSORequest(t *testing.T) {
1094+
test := NewIdentityProviderTest(t, applyKey)
1095+
w := httptest.NewRecorder()
1096+
1097+
const validRequest = `lJJBayoxFIX%2FypC9JhnU5wszAz7lgWCLaNtFd5fMbQ1MkmnunVb%2FfUfbUqEgdhs%2BTr5zkmLW8S5s8KVD4mzvm0Cl6FIwEciRCeCRDFuznd2sTD5Upk2Ro42NyGZEmNjFMI%2BBOo9pi%2BnVWbzfrEqxY27JSEntEPfg2waHNnpJ4JtcgiWRLfoLXYBjwDfu6p%2B8JIoiWy5K4eqBUipXIzVRUwXKKtRK53qkJ3qqQVuNPUjU4TIQQ%2BBS5EqPBzofKH2ntBn%2FMervo8jWnyX%2BuVC78FwKkT1gopNKX1JUxSklXTMIfM0gsv8xeeDL%2BPGk7%2FF0Qg0GdnwQ1cW5PDLUwFDID6uquO1Dlot1bJw9%2FPLRmia%2BzRMCYyk4dSiq6205QSDXOxfy3KAq5Pkvqt4DAAD%2F%2Fw%3D%3D`
1098+
1099+
r, _ := http.NewRequest("GET", "https://idp.example.com/saml/sso?RelayState=ThisIsTheRelayState&"+
1100+
"SAMLRequest="+validRequest, nil)
1101+
test.IDP.Handler().ServeHTTP(w, r)
1102+
assert.Check(t, is.Equal(http.StatusOK, w.Code))
1103+
1104+
// rejects requests that are invalid
1105+
w = httptest.NewRecorder()
1106+
r, _ = http.NewRequest("GET", "https://idp.example.com/saml/sso?RelayState=ThisIsTheRelayState&"+
1107+
"SAMLRequest=PEF1dGhuUmVxdWVzdA%3D%3D", nil)
1108+
test.IDP.Handler().ServeHTTP(w, r)
1109+
assert.Check(t, is.Equal(http.StatusBadRequest, w.Code))
1110+
1111+
// rejects requests that contain malformed XML
1112+
{
1113+
a, _ := url.QueryUnescape(validRequest)
1114+
b, _ := base64.StdEncoding.DecodeString(a)
1115+
c, _ := io.ReadAll(flate.NewReader(bytes.NewReader(b)))
1116+
d := bytes.Replace(c, []byte("<AuthnRequest"), []byte("<AuthnRequest ::foo=\"bar\">]]"), 1)
1117+
f := bytes.Buffer{}
1118+
e, _ := flate.NewWriter(&f, flate.DefaultCompression)
1119+
_, err := e.Write(d)
1120+
assert.Check(t, err)
1121+
err = e.Close()
1122+
assert.Check(t, err)
1123+
g := base64.StdEncoding.EncodeToString(f.Bytes())
1124+
invalidRequest := url.QueryEscape(g)
1125+
1126+
w = httptest.NewRecorder()
1127+
r, _ = http.NewRequest("GET", "https://idp.example.com/saml/sso?RelayState=ThisIsTheRelayState&"+
1128+
"SAMLRequest="+invalidRequest, nil)
1129+
test.IDP.Handler().ServeHTTP(w, r)
1130+
assert.Check(t, is.Equal(http.StatusBadRequest, w.Code))
1131+
}
1132+
}

samlidp/util.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/xml"
66
"errors"
77
"io"
8-
"io/ioutil"
98

109
xrv "github.com/mattermost/xml-roundtrip-validator"
1110

@@ -22,7 +21,7 @@ func randomBytes(n int) []byte {
2221

2322
func getSPMetadata(r io.Reader) (spMetadata *saml.EntityDescriptor, err error) {
2423
var data []byte
25-
if data, err = ioutil.ReadAll(r); err != nil {
24+
if data, err = io.ReadAll(r); err != nil {
2625
return nil, err
2726
}
2827

samlidp/util_go116_test.go

-26
This file was deleted.

samlidp/util_go117_test.go samlidp/util_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import (
88
"testing"
99

1010
"gotest.tools/assert"
11-
is "gotest.tools/assert/cmp"
1211
)
1312

1413
func TestGetSPMetadata(t *testing.T) {
1514
good := "" +
16-
"<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" +
15+
"<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" +
1716
"</EntityDescriptor>"
1817
_, err := getSPMetadata(strings.NewReader(good))
1918
assert.Check(t, err)
@@ -22,5 +21,5 @@ func TestGetSPMetadata(t *testing.T) {
2221
"<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" +
2322
"</EntityDescriptor>"
2423
_, err = getSPMetadata(strings.NewReader(bad))
25-
assert.Check(t, is.Error(err, "XML syntax error on line 1: unescaped ]]> not in CDATA section"))
24+
assert.Check(t, err != nil)
2625
}

samlsp/fetch_metadata.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"context"
66
"encoding/xml"
77
"errors"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"net/url"
1111

@@ -72,7 +72,7 @@ func FetchMetadata(ctx context.Context, httpClient *http.Client, metadataURL url
7272
return nil, httperr.Response(*resp)
7373
}
7474

75-
data, err := ioutil.ReadAll(resp.Body)
75+
data, err := io.ReadAll(resp.Body)
7676
if err != nil {
7777
return nil, err
7878
}

0 commit comments

Comments
 (0)