MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestInvalidKeySize

Function TestInvalidKeySize

internal/tokenization/tokenization_test.go:401–424  ·  view source on GitHub ↗

TestInvalidKeySize ensures appropriate error handling for invalid key sizes

(t *testing.T)

Source from the content-addressed store, hash-verified

399
400// TestInvalidKeySize ensures appropriate error handling for invalid key sizes
401func TestInvalidKeySize(t *testing.T) {
402 invalidSizes := []int{1, 8, 10, 20, 30, 64}
403 testValue := "Test value"
404
405 for _, size := range invalidSizes {
406 key := make([]byte, size)
407 _, err := rand.Read(key)
408 if err != nil {
409 t.Fatalf("Failed to generate random key: %v", err)
410 }
411
412 service := NewTokenizationService(key)
413 _, err = service.Tokenize(testValue)
414
415 // AES only accepts key sizes of 16, 24, or 32 bytes
416 if size == 16 || size == 24 || size == 32 {
417 if err != nil {
418 t.Errorf("Expected success with %d-byte key, got error: %v", size, err)
419 }
420 } else if err == nil {
421 t.Errorf("Expected error with invalid %d-byte key, got nil", size)
422 }
423 }
424}
425
426// TestUTF8Tokenization tests tokenization with UTF-8 characters
427func TestUTF8Tokenization(t *testing.T) {

Callers

nothing calls this directly

Calls 2

TokenizeMethod · 0.95
NewTokenizationServiceFunction · 0.85

Tested by

no test coverage detected