fix: bug with authorizer url
This commit is contained in:
@@ -7,13 +7,12 @@ import (
|
||||
"github.com/authorizerdev/authorizer/server/envstore"
|
||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||
"github.com/authorizerdev/authorizer/server/resolvers"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func adminSignupTests(t *testing.T, s TestSetup) {
|
||||
t.Helper()
|
||||
t.Run(`should complete admin login`, func(t *testing.T) {
|
||||
t.Run(`should complete admin signup`, func(t *testing.T) {
|
||||
_, ctx := createContext(s)
|
||||
_, err := resolvers.AdminSignupResolver(ctx, model.AdminSignupInput{
|
||||
AdminSecret: "admin",
|
||||
@@ -24,7 +23,7 @@ func adminSignupTests(t *testing.T, s TestSetup) {
|
||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeyAdminSecret, "")
|
||||
|
||||
_, err = resolvers.AdminSignupResolver(ctx, model.AdminSignupInput{
|
||||
AdminSecret: uuid.New().String(),
|
||||
AdminSecret: "admin123",
|
||||
})
|
||||
|
||||
assert.Nil(t, err)
|
||||
|
@@ -14,16 +14,13 @@ func TestEnvs(t *testing.T) {
|
||||
env.InitEnv()
|
||||
store := envstore.EnvInMemoryStoreObj.GetEnvStoreClone()
|
||||
|
||||
assert.Equal(t, store.StringEnv[constants.EnvKeyAdminSecret], "admin")
|
||||
assert.Equal(t, store.StringEnv[constants.EnvKeyEnv], "production")
|
||||
assert.False(t, store.BoolEnv[constants.EnvKeyDisableEmailVerification])
|
||||
assert.False(t, store.BoolEnv[constants.EnvKeyDisableMagicLinkLogin])
|
||||
assert.False(t, store.BoolEnv[constants.EnvKeyDisableBasicAuthentication])
|
||||
assert.Equal(t, store.StringEnv[constants.EnvKeyJwtType], "HS256")
|
||||
assert.Equal(t, store.StringEnv[constants.EnvKeyJwtSecret], "random_string")
|
||||
assert.Equal(t, store.StringEnv[constants.EnvKeyJwtRoleClaim], "role")
|
||||
assert.EqualValues(t, store.SliceEnv[constants.EnvKeyRoles], []string{"user"})
|
||||
assert.EqualValues(t, store.SliceEnv[constants.EnvKeyDefaultRoles], []string{"user"})
|
||||
assert.EqualValues(t, store.SliceEnv[constants.EnvKeyProtectedRoles], []string{"admin"})
|
||||
assert.EqualValues(t, store.SliceEnv[constants.EnvKeyAllowedOrigins], []string{"*"})
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"log"
|
||||
"testing"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
@@ -20,20 +21,20 @@ func TestResolvers(t *testing.T) {
|
||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeyDatabaseURL, dbURL)
|
||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeyDatabaseType, dbType)
|
||||
|
||||
env.InitEnv()
|
||||
s := testSetup()
|
||||
defer s.Server.Close()
|
||||
|
||||
db.InitDB()
|
||||
|
||||
// clean the persisted config for test to use fresh config
|
||||
envData, err := db.Provider.GetEnv()
|
||||
log.Println("=> envData:", envstore.EnvInMemoryStoreObj.GetEnvStoreClone())
|
||||
if err == nil {
|
||||
envData.EnvData = ""
|
||||
db.Provider.UpdateEnv(envData)
|
||||
}
|
||||
env.PersistEnv()
|
||||
|
||||
s := testSetup()
|
||||
defer s.Server.Close()
|
||||
|
||||
t.Run("should pass tests for "+dbType, func(t *testing.T) {
|
||||
// admin tests
|
||||
adminSignupTests(t, s)
|
||||
|
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/authorizerdev/authorizer/server/handlers"
|
||||
"github.com/authorizerdev/authorizer/server/middlewares"
|
||||
"github.com/authorizerdev/authorizer/server/sessionstore"
|
||||
"github.com/gin-contrib/location"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -73,13 +72,17 @@ func testSetup() TestSetup {
|
||||
}
|
||||
|
||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeyEnvPath, "../../.env.sample")
|
||||
|
||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeySmtpHost, "smtp.yopmail.com")
|
||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeySmtpPort, "2525")
|
||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeySmtpUsername, "lakhan@yopmail.com")
|
||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeySmtpPassword, "test")
|
||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.StringStoreIdentifier, constants.EnvKeySenderEmail, "info@yopmail.com")
|
||||
envstore.EnvInMemoryStoreObj.UpdateEnvVariable(constants.SliceStoreIdentifier, constants.EnvKeyProtectedRoles, []string{"admin"})
|
||||
env.InitEnv()
|
||||
sessionstore.InitSession()
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
c, r := gin.CreateTestContext(w)
|
||||
r.Use(location.Default())
|
||||
r.Use(middlewares.GinContextToContextMiddleware())
|
||||
r.Use(middlewares.CORSMiddleware())
|
||||
|
||||
|
@@ -24,7 +24,7 @@ func updateUserTest(t *testing.T, s TestSetup) {
|
||||
})
|
||||
|
||||
user := *signupRes.User
|
||||
adminRole := "admin"
|
||||
adminRole := "supplier"
|
||||
userRole := "user"
|
||||
newRoles := []*string{&adminRole, &userRole}
|
||||
_, err := resolvers.UpdateUserResolver(ctx, model.UpdateUserInput{
|
||||
|
@@ -8,9 +8,9 @@ import (
|
||||
)
|
||||
|
||||
func TestGetHostName(t *testing.T) {
|
||||
authorizer_url := "http://test.herokuapp.com:80"
|
||||
url := "http://test.herokuapp.com:80"
|
||||
|
||||
host, port := utils.GetHostParts(authorizer_url)
|
||||
host, port := utils.GetHostParts(url)
|
||||
expectedHost := "test.herokuapp.com"
|
||||
|
||||
assert.Equal(t, host, expectedHost, "hostname should be equal")
|
||||
@@ -18,9 +18,9 @@ func TestGetHostName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDomainName(t *testing.T) {
|
||||
authorizer_url := "http://test.herokuapp.com"
|
||||
url := "http://test.herokuapp.com"
|
||||
|
||||
got := utils.GetDomainName(authorizer_url)
|
||||
got := utils.GetDomainName(url)
|
||||
want := "herokuapp.com"
|
||||
|
||||
assert.Equal(t, got, want, "domain name should be equal")
|
||||
|
Reference in New Issue
Block a user