fix: rename config -> env and handle env interface better

This commit is contained in:
Lakhan Samani
2022-01-20 16:52:37 +05:30
parent 7785f98dcd
commit 38419a4ef4
60 changed files with 668 additions and 610 deletions

View File

@@ -0,0 +1,54 @@
package test
import (
"fmt"
"log"
"testing"
"github.com/authorizerdev/authorizer/server/constants"
"github.com/authorizerdev/authorizer/server/envstore"
"github.com/authorizerdev/authorizer/server/graph/model"
"github.com/authorizerdev/authorizer/server/resolvers"
"github.com/authorizerdev/authorizer/server/utils"
"github.com/stretchr/testify/assert"
)
func updateEnvTests(t *testing.T, s TestSetup) {
t.Helper()
t.Run(`should update envs`, func(t *testing.T) {
req, ctx := createContext(s)
originalAppURL := envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAppURL)
data := model.UpdateEnvInput{}
_, err := resolvers.UpdateEnvResolver(ctx, data)
log.Println("error:", err)
assert.NotNil(t, err)
h, err := utils.EncryptPassword(envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAdminSecret))
assert.Nil(t, err)
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAdminCookieName), h))
newURL := "https://test.com"
disableLoginPage := true
allowedOrigins := []string{"http://localhost:8080"}
data = model.UpdateEnvInput{
AppURL: &newURL,
DisableLoginPage: &disableLoginPage,
AllowedOrigins: allowedOrigins,
}
_, err = resolvers.UpdateEnvResolver(ctx, data)
assert.Nil(t, err)
assert.Equal(t, envstore.EnvInMemoryStoreObj.GetStringStoreEnvVariable(constants.EnvKeyAppURL), newURL)
assert.True(t, envstore.EnvInMemoryStoreObj.GetBoolStoreEnvVariable(constants.EnvKeyDisableLoginPage))
assert.Equal(t, envstore.EnvInMemoryStoreObj.GetSliceStoreEnvVariable(constants.EnvKeyAllowedOrigins), allowedOrigins)
disableLoginPage = false
data = model.UpdateEnvInput{
AppURL: &originalAppURL,
DisableLoginPage: &disableLoginPage,
AllowedOrigins: []string{"*"},
}
_, err = resolvers.UpdateEnvResolver(ctx, data)
assert.Nil(t, err)
})
}