-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathLtiVerifierAndSignerTest.java
More file actions
61 lines (43 loc) · 1.76 KB
/
LtiVerifierAndSignerTest.java
File metadata and controls
61 lines (43 loc) · 1.76 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 org.imsglobal.lti.launch;
import org.apache.http.HttpRequest;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.junit.Test;
import static org.junit.Assert.*;
import java.net.URI;
import java.util.*;
/**
* @author Paul Gray
*/
public class LtiVerifierAndSignerTest {
LtiVerifier verifier = new LtiOauthVerifier();
LtiSigner signer = new LtiOauthSigner();
@Test
public void verifierShouldVerifyCorrectlySignedLtiLaunches() throws Exception {
String key = "key";
String secret = "secret";
HttpPost ltiLaunch = new HttpPost(new URI("http://example.com/test"));
signer.sign(ltiLaunch, key, secret);
LtiVerificationResult result = verifier.verify(new MockHttpPost(ltiLaunch), secret);
assertTrue(result.getSuccess());
}
@Test
public void verifierShouldRejectIncorrectlySignedLtiLaunches() throws Exception {
String key = "key";
String secret = "secret";
HttpPost ltiLaunch = new HttpPost(new URI("http://example.com/test"));
signer.sign(ltiLaunch, key, secret);
LtiVerificationResult result = verifier.verify(new MockHttpPost(ltiLaunch), "wrongSecret");
assertFalse(result.getSuccess());
}
@Test
public void verifierShouldVerifyCorrectlySignedLtiGetServiceRequests() throws Exception {
String key = "key";
String secret = "secret";
HttpGet ltiServiceGetRequest = new HttpGet(new URI("http://example.com/test"));
signer.sign(ltiServiceGetRequest, key, secret);
LtiVerificationResult result = verifier.verify(new MockHttpGet(ltiServiceGetRequest), secret);
assertTrue(result.getSuccess());
}
}