diff --git a/pkg/crypt/crypt_internal_test.go b/pkg/crypt/crypt_internal_test.go new file mode 100644 index 0000000..0b9c288 --- /dev/null +++ b/pkg/crypt/crypt_internal_test.go @@ -0,0 +1,24 @@ +package crypt + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestEnsureRSA_Good(t *testing.T) { + s := &Service{} + assert.Nil(t, s.rsa, "s.rsa should be nil initially") + s.ensureRSA() + assert.NotNil(t, s.rsa, "s.rsa should not be nil after ensureRSA()") +} + +func TestEnsureRSA_Bad(t *testing.T) { + // Not really a "bad" case here in terms of invalid input, + // but we can test that calling it twice is safe. + s := &Service{} + s.ensureRSA() + rsaInstance := s.rsa + s.ensureRSA() + assert.Same(t, rsaInstance, s.rsa, "s.rsa should be the same instance after second call") +} diff --git a/pkg/crypt/std/lthn/lthn_internal_test.go b/pkg/crypt/std/lthn/lthn_internal_test.go new file mode 100644 index 0000000..bd19860 --- /dev/null +++ b/pkg/crypt/std/lthn/lthn_internal_test.go @@ -0,0 +1,37 @@ +package lthn + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCreateSalt_Good(t *testing.T) { + // "hello" reversed: "olleh" -> "0113h" + expected := "0113h" + actual := createSalt("hello") + assert.Equal(t, expected, actual, "Salt should be correctly created for 'hello'") +} + +func TestCreateSalt_Bad(t *testing.T) { + // Test with an empty string + expected := "" + actual := createSalt("") + assert.Equal(t, expected, actual, "Salt for an empty string should be empty") +} + +func TestCreateSalt_Ugly(t *testing.T) { + // Test with characters not in the keyMap + input := "world123" + // "world123" reversed: "321dlrow" -> "e2ld1r0w" + expected := "e2ld1r0w" + actual := createSalt(input) + assert.Equal(t, expected, actual, "Salt should handle characters not in the keyMap") + + // Test with only characters in the keyMap + input = "oleta" + // "oleta" reversed: "atelo" -> "47310" + expected = "47310" + actual = createSalt(input) + assert.Equal(t, expected, actual, "Salt should correctly handle strings with only keyMap characters") +}