package cryptography import ( "encoding/base64" "testing" "github.com/stretchr/testify/assert" ) func TestIsBase64StdValid(t *testing.T) { cases := []struct { name string input string }{ {"non-empty", base64.StdEncoding.EncodeToString([]byte("hello"))}, {"longer", base64.StdEncoding.EncodeToString([]byte("hello, world!"))}, // Note: empty string encodes to "" which IsBase64Std("") returns false (early exit) } for _, tc := range cases { assert.True(t, IsBase64Std(tc.input), "expected %q to be valid base64", tc.input) } } func TestIsBase64StdEmptyString(t *testing.T) { assert.False(t, IsBase64Std("")) } func TestIsBase64StdInvalidChars(t *testing.T) { assert.False(t, IsBase64Std("not-base64!!!")) } func TestIsBase64StdWrongPadding(t *testing.T) { // "aGVsbG8" is base64url without padding – standard decoder requires padding assert.False(t, IsBase64Std("aGVsbG8")) } func TestIsBase64StdWhitespaceOnly(t *testing.T) { // " " → TrimSpace → "" → len % 4 == 0 → attempts decode → succeeds → true // IsBase64Std trims leading/trailing whitespace, so all-whitespace passes // because empty string decodes without error. Document actual behaviour: assert.True(t, IsBase64Std(" ")) } func TestIsBase64StdPaddedBase64(t *testing.T) { // Standard base64 with padding assert.True(t, IsBase64Std("aGVsbG8=")) }