-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathLtiOauthVerifierTest.java
More file actions
77 lines (55 loc) · 2.98 KB
/
LtiOauthVerifierTest.java
File metadata and controls
77 lines (55 loc) · 2.98 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package org.imsglobal.lti.launch;
import org.apache.http.client.methods.HttpPost;
import org.codehaus.jackson.map.ser.std.IterableSerializer;
import org.junit.Test;
import java.net.URI;
import java.util.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Created by paul on 9/27/17.
*/
public class LtiOauthVerifierTest {
LtiVerifier verifier = new LtiOauthVerifier();
LtiSigner signer = new LtiOauthSigner();
@Test
public void verifierShouldAllowUrlParametersInUrlParam() throws Exception {
String baseUrl = "http://example.com/test";
String urlParams = "?bestLanguage=java";
String key = "key";
String secret = "secret";
Collection<AbstractMap.SimpleEntry<String, String>> myEntries = Arrays.asList(
new AbstractMap.SimpleEntry<String, String>("hm", "okasy"),
new AbstractMap.SimpleEntry<String, String>("hm", "asdf"),
new AbstractMap.SimpleEntry<String, String>("wat", "asdfasdff")
);
Collection signedParameters = signer.signParameters(myEntries, key, secret, baseUrl + urlParams, "GET");
// including the parameters in the url should yield success
LtiVerificationResult successResult = verifier.verifyParameters(signedParameters, baseUrl + urlParams, "GET", secret);
assertTrue(successResult.getSuccess());
// omitting the parameters in the url should yield failure
LtiVerificationResult failResult = verifier.verifyParameters(signedParameters, baseUrl, "GET", secret);
assertFalse(failResult.getSuccess());
}
@Test
public void verifierShouldAllowUrlParametersInEntryMap() throws Exception {
String baseUrl = "http://example.com/test";
String urlParams = "?bestLanguage=java";
String key = "key";
String secret = "secret";
List<AbstractMap.SimpleEntry<String, String>> myEntries = Arrays.asList(
new AbstractMap.SimpleEntry<String, String>("hm", "okasy"),
new AbstractMap.SimpleEntry<String, String>("hm", "asdf"),
new AbstractMap.SimpleEntry<String, String>("wat", "asdfasdff")
);
Collection signedParameters = signer.signParameters(myEntries, key, secret, baseUrl + urlParams, "GET");
List signedParamsWithUrlParams = new ArrayList<>(signedParameters);
signedParamsWithUrlParams.add(new AbstractMap.SimpleEntry<String, String>("bestLanguage", "java"));
// including the url parameters in the entries map should yield success
LtiVerificationResult successResult = verifier.verifyParameters(signedParamsWithUrlParams, baseUrl, "GET", secret);
assertTrue(successResult.getSuccess());
// omitting the url parameters in the entries map and omitting them in the url should yield failure
LtiVerificationResult failResult = verifier.verifyParameters(signedParameters, baseUrl, "GET", secret);
assertFalse(failResult.getSuccess());
}
}