File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717# See https://github.com/cristalhq/.github/.github/workflows
1818jobs :
1919 build :
20- uses : cristalhq/.github/.github/workflows/build.yml@main
21-
22- codeql :
23- uses : cristalhq/.github/.github/workflows/codeql.yml@main
20+ uses : cristalhq/.github/.github/workflows/build.yml@3f2ea32d08cea472a5d81a15769eb911595118af # v0.2.1
2421
2522 vuln :
26- uses : cristalhq/.github/.github/workflows/vuln.yml@main
23+ uses : cristalhq/.github/.github/workflows/vuln.yml@3f2ea32d08cea472a5d81a15769eb911595118af # v0.2.1
2724
2825 release :
2926 if : github.event_name == 'workflow_dispatch'
30- uses : cristalhq/.github/.github/workflows/release.yml@main
27+ uses : cristalhq/.github/.github/workflows/release.yml@3f2ea32d08cea472a5d81a15769eb911595118af # v0.2.1
3128 with :
3229 tag : ${{ github.event.input.tag }}
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ func WithContentType(cty string) BuilderOption {
1919}
2020
2121// Builder is used to create a new token.
22+ // Safe to use concurrently.
2223type Builder struct {
2324 signer Signer
2425 header Header
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package jwt
22
33import (
44 "errors"
5+ "sync"
56 "testing"
67)
78
@@ -226,6 +227,42 @@ func TestBuildMalformed(t *testing.T) {
226227 )
227228}
228229
230+ func TestBuilderConcurrently (t * testing.T ) {
231+ signer , err := NewSignerHS (HS256 , []byte ("test-key" ))
232+ if err != nil {
233+ t .Fatal (err )
234+ }
235+
236+ builder := NewBuilder (signer )
237+
238+ errCh := make (chan error , 10 )
239+ claims := "string-claims"
240+
241+ var wg sync.WaitGroup
242+ wg .Add (10 )
243+ for i := 0 ; i < 10 ; i ++ {
244+ go func () {
245+ defer wg .Done ()
246+
247+ token , err := builder .Build (claims )
248+ errCh <- err
249+
250+ if token .String () == "" {
251+ panic ("should not be empty" )
252+ }
253+ }()
254+ }
255+
256+ wg .Wait ()
257+ close (errCh )
258+
259+ for err := range errCh {
260+ if err != nil {
261+ t .Fatal (err )
262+ }
263+ }
264+ }
265+
229266type badSigner struct {}
230267
231268func (badSigner ) SignSize () int {
You can’t perform that action at this time.
0 commit comments