Skip to content

Commit

Permalink
Merge pull request #1274 from Permify/next
Browse files Browse the repository at this point in the history
test: add Authenticate Id Token test cases for OIDC authentication
  • Loading branch information
tolgaOzen committed May 30, 2024
2 parents 255961f + d00629c commit eb9519f
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/api-reference/apidocs.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "Permify API",
"description": "Permify is an open source authorization service for creating fine-grained and scalable authorization systems.",
"version": "v0.8.8",
"version": "v0.9.0",
"contact": {
"name": "API Support",
"url": "https://github.com/Permify/permify/issues",
Expand Down
50 changes: 50 additions & 0 deletions internal/authn/oidc/authn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
. "github.com/onsi/gomega"

"github.com/Permify/permify/internal/config"
base `github.com/Permify/permify/pkg/pb/base/v1`
)

var _ = Describe("authn-oidc", func() {
Expand Down Expand Up @@ -240,6 +241,55 @@ var _ = Describe("authn-oidc", func() {
Expect(err).ShouldNot(Equal(BeNil()))
})
})

Context("Authenticate Id Token", func() {
It("Case 1", func() {
// create authenticator
ctx := context.Background()
auth, err := NewOidcAuthn(ctx, config.Oidc{
Audience: audience,
Issuer: issuerURL,
})
Expect(err).To(BeNil())

// authenticate
niceMd := make(metautils.NiceMD)
niceMd.Set("authorization", "Bearer ")
err = auth.Authenticate(niceMd.ToIncoming(ctx))
Expect(err.Error()).Should(Equal(base.ErrorCode_ERROR_CODE_INVALID_BEARER_TOKEN.String()))
})

It("Case 2", func() {
// create authenticator
ctx := context.Background()
auth, err := NewOidcAuthn(ctx, config.Oidc{
Audience: audience,
Issuer: issuerURL,
})
Expect(err).To(BeNil())

// authenticate
niceMd := make(metautils.NiceMD)
err = auth.Authenticate(niceMd.ToIncoming(ctx))
Expect(err.Error()).Should(Equal(base.ErrorCode_ERROR_CODE_MISSING_BEARER_TOKEN.String()))
})

It("Case 3", func() {
// create authenticator
ctx := context.Background()
auth, err := NewOidcAuthn(ctx, config.Oidc{
Audience: audience,
Issuer: issuerURL,
})
Expect(err).To(BeNil())

// authenticate
niceMd := make(metautils.NiceMD)
niceMd.Set("authorization", "Bearer asd")
err = auth.Authenticate(niceMd.ToIncoming(ctx))
Expect(err.Error()).Should(Equal(base.ErrorCode_ERROR_CODE_INVALID_BEARER_TOKEN.String()))
})
})
})

func claimOverride(current, overrider *jwt.RegisteredClaims) {
Expand Down
2 changes: 1 addition & 1 deletion internal/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var Identifier = ""
*/
const (
// Version is the last release of the Permify (e.g. v0.1.0)
Version = "v0.8.8"
Version = "v0.9.0"
)

// Function to create a single line of the ASCII art with centered content and color
Expand Down
4 changes: 4 additions & 0 deletions internal/storage/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/Permify/permify/internal/config"
"github.com/Permify/permify/internal/storage"
"github.com/Permify/permify/internal/storage/postgres/utils"
"github.com/Permify/permify/pkg/database"
PQDatabase "github.com/Permify/permify/pkg/database/postgres"
)
Expand Down Expand Up @@ -85,6 +86,9 @@ func postgresDB(postgresVersion string) database.Database {
PQDatabase.MaxConnectionLifeTime(cfg.MaxConnectionLifetime),
)

_, err = utils.EnsureDBVersion(db.(*PQDatabase.Postgres).WritePool)
Expect(err).ShouldNot(HaveOccurred())

return db
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/pb/base/v1/openapi.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/base/v1/openapi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: {
title: "Permify API";
description: "Permify is an open source authorization service for creating fine-grained and scalable authorization systems.";
version: "v0.8.8";
version: "v0.9.0";
contact: {
name: "API Support";
url: "https://github.com/Permify/permify/issues";
Expand Down

0 comments on commit eb9519f

Please sign in to comment.