-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLocalResponseV1Test.java
More file actions
61 lines (53 loc) · 2.11 KB
/
LocalResponseV1Test.java
File metadata and controls
61 lines (53 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.mindee.input;
import static com.mindee.TestingUtilities.getV1ResourcePath;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class LocalResponseV1Test {
/**
* Fake secret key.
*/
String secretKey = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH";
/**
* Real signature using fake secret key.
*/
String signature = "5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0";
/**
* File which the signature applies to.
*/
Path filePath = getV1ResourcePath("async/get_completed_empty.json");
@Test
void loadDocument_withFile_mustReturnValidLocalResponse() throws IOException {
LocalResponse localResponse = new LocalResponse(new File(this.filePath.toString()));
Assertions.assertNotNull(localResponse.getFile());
Assertions
.assertFalse(
localResponse.isValidHmacSignature(this.secretKey, "invalid signature is invalid")
);
Assertions.assertEquals(this.signature, localResponse.getHmacSignature(this.secretKey));
Assertions.assertTrue(localResponse.isValidHmacSignature(this.secretKey, this.signature));
}
@Test
void loadDocument_withString_mustReturnValidLocalResponse() {
LocalResponse localResponse = new LocalResponse("{'some': 'json', 'with': 'data'}");
Assertions.assertNotNull(localResponse.getFile());
Assertions
.assertFalse(
localResponse.isValidHmacSignature(this.secretKey, "invalid signature is invalid")
);
}
@Test
void loadDocument_withInputStream_mustReturnValidLocalResponse() throws IOException {
LocalResponse localResponse = new LocalResponse(Files.newInputStream(this.filePath));
Assertions.assertNotNull(localResponse.getFile());
Assertions
.assertFalse(
localResponse.isValidHmacSignature(this.secretKey, "invalid signature is invalid")
);
Assertions.assertEquals(this.signature, localResponse.getHmacSignature(this.secretKey));
Assertions.assertTrue(localResponse.isValidHmacSignature(this.secretKey, this.signature));
}
}