drasl/common_test.go
Evan Goode 5c1f6c1cfa
Implement SSO via OIDC (#127)
Resolves https://github.com/unmojang/drasl/issues/39

* Use __Host- cookie prefix instead of setting Domain

See https://stackoverflow.com/a/64735551

* Unlinking OIDC accounts

* AllowPasswordLogin, OIDC docs, cleanup

* YggdrasilError

* Migrate existing password users without login

* API query/create/delete user OIDC identities

* test APICreateOIDCIdentity

* test APIDeleteeOIDCIdentity

* API Create users with OIDC identities

* OIDC: PKCE

* Use YggdrasilError in authlib-injector routes

* OIDC: AllowChoosingPlayerName

* recipes.md: Update for OIDC and deprecated config options

* OIDC: fix APICreateUser without password, validate oidcIdentities

* OIDC: error at complete-registration if no preferred player name

* Proper error pages

* MC_ prefix for Minecraft Tokens
2025-03-22 16:40:26 -04:00

41 lines
936 B
Go

package main
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestCommon(t *testing.T) {
t.Parallel()
ts := &TestSuite{}
config := testConfig()
ts.Setup(config)
defer ts.Teardown()
t.Run("AEAD encrypt/decrypt", ts.testAEADEncryptDecrypt)
t.Run("Encrypt/decrypt cookie value", ts.testEncryptDecryptCookieValue)
}
func (ts *TestSuite) testAEADEncryptDecrypt(t *testing.T) {
plaintext := []byte("I am a cookie value")
ciphertext, err := ts.App.AEADEncrypt(plaintext)
assert.Nil(t, err)
decrypted, err := ts.App.AEADDecrypt(ciphertext)
assert.Nil(t, err)
assert.Equal(t, plaintext, decrypted)
}
func (ts *TestSuite) testEncryptDecryptCookieValue(t *testing.T) {
plaintext := "I am a cookie value"
ciphertext, err := ts.App.EncryptCookieValue(plaintext)
assert.Nil(t, err)
decrypted, err := ts.App.DecryptCookieValue(ciphertext)
assert.Nil(t, err)
assert.Equal(t, plaintext, string(decrypted))
}