(t *testing.T, encoding string, testCases []EncodingTestCase, caseInsensitive bool)
| 428 | } |
| 429 | |
| 430 | func testStandardDecryptFileName(t *testing.T, encoding string, testCases []EncodingTestCase, caseInsensitive bool) { |
| 431 | enc, _ := NewNameEncoding(encoding) |
| 432 | for _, test := range testCases { |
| 433 | // Test when dirNameEncrypt=true |
| 434 | c, _ := newCipher(NameEncryptionStandard, "", "", true, enc) |
| 435 | actual, actualErr := c.DecryptFileName(test.in) |
| 436 | assert.NoError(t, actualErr) |
| 437 | assert.Equal(t, test.expected, actual) |
| 438 | if caseInsensitive { |
| 439 | c, _ := newCipher(NameEncryptionStandard, "", "", true, enc) |
| 440 | actual, actualErr := c.DecryptFileName(strings.ToUpper(test.in)) |
| 441 | assert.NoError(t, actualErr) |
| 442 | assert.Equal(t, test.expected, actual) |
| 443 | } |
| 444 | // Add a character should raise ErrorNotAMultipleOfBlocksize |
| 445 | actual, actualErr = c.DecryptFileName(enc.EncodeToString([]byte("1")) + test.in) |
| 446 | assert.Equal(t, ErrorNotAMultipleOfBlocksize, actualErr) |
| 447 | assert.Equal(t, "", actual) |
| 448 | // Test when dirNameEncrypt=false |
| 449 | noDirEncryptIn := test.in |
| 450 | if strings.LastIndex(test.expected, "/") != -1 { |
| 451 | noDirEncryptIn = test.expected[:strings.LastIndex(test.expected, "/")] + test.in[strings.LastIndex(test.in, "/"):] |
| 452 | } |
| 453 | c, _ = newCipher(NameEncryptionStandard, "", "", false, enc) |
| 454 | actual, actualErr = c.DecryptFileName(noDirEncryptIn) |
| 455 | assert.NoError(t, actualErr) |
| 456 | assert.Equal(t, test.expected, actual) |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | func TestStandardDecryptFileNameBase32(t *testing.T) { |
| 461 | testStandardDecryptFileName(t, "base32", []EncodingTestCase{ |
no test coverage detected
searching dependent graphs…