(t *testing.T)
| 482 | } |
| 483 | |
| 484 | func TestNonStandardDecryptFileName(t *testing.T) { |
| 485 | for _, encoding := range []string{"base32", "base64", "base32768"} { |
| 486 | enc, _ := NewNameEncoding(encoding) |
| 487 | for _, test := range []struct { |
| 488 | mode NameEncryptionMode |
| 489 | dirNameEncrypt bool |
| 490 | in string |
| 491 | expected string |
| 492 | expectedErr error |
| 493 | customSuffix string |
| 494 | }{ |
| 495 | {NameEncryptionOff, true, "1/12/123.bin", "1/12/123", nil, ""}, |
| 496 | {NameEncryptionOff, true, "1/12/123.bix", "", ErrorNotAnEncryptedFile, ""}, |
| 497 | {NameEncryptionOff, true, ".bin", "", ErrorNotAnEncryptedFile, ""}, |
| 498 | {NameEncryptionOff, true, "1/12/123-v2001-02-03-040506-123.bin", "1/12/123-v2001-02-03-040506-123", nil, ""}, |
| 499 | {NameEncryptionOff, true, "1/12/123-v1970-01-01-010101-123-v2001-02-03-040506-123.bin", "1/12/123-v1970-01-01-010101-123-v2001-02-03-040506-123", nil, ""}, |
| 500 | {NameEncryptionOff, true, "1/12/123-v1970-01-01-010101-123-v2001-02-03-040506-123.txt.bin", "1/12/123-v1970-01-01-010101-123-v2001-02-03-040506-123.txt", nil, ""}, |
| 501 | {NameEncryptionOff, true, "1/12/123.jpg", "1/12/123", nil, ".jpg"}, |
| 502 | {NameEncryptionOff, true, "1/12/123", "1/12/123", nil, "none"}, |
| 503 | {NameEncryptionObfuscated, true, "!.hello", "hello", nil, ""}, |
| 504 | {NameEncryptionObfuscated, true, "hello", "", ErrorNotAnEncryptedFile, ""}, |
| 505 | {NameEncryptionObfuscated, true, "161.\u00e4", "\u00a1", nil, ""}, |
| 506 | {NameEncryptionObfuscated, true, "160.\u03c2", "\u03a0", nil, ""}, |
| 507 | {NameEncryptionObfuscated, false, "1/12/123/53.!!lipps", "1/12/123/!hello", nil, ""}, |
| 508 | {NameEncryptionObfuscated, false, "1/12/123/53-v2001-02-03-040506-123.!!lipps", "1/12/123/!hello-v2001-02-03-040506-123", nil, ""}, |
| 509 | } { |
| 510 | c, _ := newCipher(test.mode, "", "", test.dirNameEncrypt, enc) |
| 511 | if test.customSuffix != "" { |
| 512 | c.setEncryptedSuffix(test.customSuffix) |
| 513 | } |
| 514 | actual, actualErr := c.DecryptFileName(test.in) |
| 515 | what := fmt.Sprintf("Testing %q (mode=%v)", test.in, test.mode) |
| 516 | assert.Equal(t, test.expected, actual, what) |
| 517 | assert.Equal(t, test.expectedErr, actualErr, what) |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | func TestEncDecMatches(t *testing.T) { |
| 523 | for _, encoding := range []string{"base32", "base64", "base32768"} { |
nothing calls this directly
no test coverage detected
searching dependent graphs…