Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giftkugel committed Aug 27, 2024
1 parent b76d45a commit 345fda3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/server/handler/keys/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package keys
import (
"encoding/json"
"fmt"
"github.com/lestrrat-go/jwx/v2/jwa"
"github.com/webishdev/stopnik/internal/config"
"github.com/webishdev/stopnik/internal/endpoint"
"github.com/webishdev/stopnik/internal/manager"
"io"
"net/http"
"net/http/httptest"
"slices"
"testing"
)

Expand Down Expand Up @@ -83,6 +85,30 @@ func testKeys(t *testing.T, testConfig *config.Config) {
if len(keys.Keys) != 3 {
t.Errorf("handler returned wrong number of keys: got %v want %v", len(keys.Keys), 3)
}

containsES512 := slices.ContainsFunc(keys.Keys, func(r responseKeys) bool {
return r.Alg == string(jwa.ES512)
})

if !containsES512 {
t.Error("key for ES512 was missing")
}

containsES256 := slices.ContainsFunc(keys.Keys, func(r responseKeys) bool {
return r.Alg == string(jwa.ES256)
})

if !containsES256 {
t.Error("key for ES256 was missing")
}

containsRSA256 := slices.ContainsFunc(keys.Keys, func(r responseKeys) bool {
return r.Alg == string(jwa.RS256)
})

if !containsRSA256 {
t.Error("key for RS256 was missing")
}
})
}

Expand Down

0 comments on commit 345fda3

Please sign in to comment.