Skip to content

Commit

Permalink
chore: add extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Oct 31, 2024
1 parent 25ad3bd commit de86916
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 27 additions & 0 deletions alby/alby_oauth_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@ import (
"github.com/tyler-smith/go-bip39"
)

func TestExistingEncryptedBackup(t *testing.T) {
defer tests.RemoveTestService()
svc, err := tests.CreateTestService()
assert.NoError(t, err)

mnemonic := "limit reward expect search tissue call visa fit thank cream brave jump"
unlockPassword := "123"
svc.Cfg.SetUpdate("Mnemonic", mnemonic, unlockPassword)
err = svc.Keys.Init(svc.Cfg, unlockPassword)
assert.Nil(t, err)

encryptedBackup := "69defec3014a6ab9c6abc612-44266b33b8bfaa3bdee45c03dc60b659416ad957d101068607ed120c27573b6d61ad63fcfddf427d0a4f0a1e488585e57479183acb45cd7f26663d1f2de9c154b84f68b9f01f420e1b6f6ce6ae31d89f327a5b393ff49c3456994355a22fd965725523f37c393afc369001dcaf46ef2d8ef062f4bb17edc263985dfca4"

masterKey, err := bip32.NewMasterKey(bip39.NewSeed(mnemonic, ""))
assert.Nil(t, err)

appKey, err := masterKey.NewChildKey(0)
assert.Nil(t, err)
encryptedChannelsBackupKey, err := appKey.NewChildKey(0)
assert.Nil(t, err)

decrypted, err := config.AesGcmDecryptWithKey(encryptedBackup, encryptedChannelsBackupKey.Key)
assert.Nil(t, err)

assert.Equal(t, "{\"node_id\":\"037e702144c4fa485d42f0f69864e943605823763866cf4bf619d2d2cf2eda420b\",\"channels\":[],\"monitors\":[]}\n", decrypted)
}

func TestEncryptedBackup(t *testing.T) {
defer tests.RemoveTestService()
svc, err := tests.CreateTestService()
Expand Down
2 changes: 0 additions & 2 deletions config/aesgcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"encoding/hex"
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -43,7 +42,6 @@ func TestEncryptDecryptWithKey(t *testing.T) {
assert.Equal(t, "409e902eafba273b21dff921f0eb4bec6cbb0b657fdce8d245ca78d2920f8b73", hex.EncodeToString(masterKey.Key))

encrypted, err := AesGcmEncryptWithKey(plaintext, masterKey.Key)
fmt.Print(encrypted)
assert.NoError(t, err)
value, err := AesGcmDecryptWithKey(encrypted, masterKey.Key)
assert.NoError(t, err)
Expand Down

0 comments on commit de86916

Please sign in to comment.