Skip to content

Commit b88bc0d

Browse files
author
Paul Gray
committed
Adding tests for Lti Service requests
1 parent 622185a commit b88bc0d

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

src/test/java/org/imsglobal/lti/launch/BaseMockHttpServletRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.util.*;
1818

1919
/**
20-
* Created by paul on 8/24/16.
20+
* @author Paul Gray
2121
*/
2222
public abstract class BaseMockHttpServletRequest implements HttpServletRequest {
2323

src/test/java/org/imsglobal/lti/launch/LtiVerifierAndSignerTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
/**
14-
* Created by paul on 8/24/16.
14+
* @author Paul Gray
1515
*/
1616
public class LtiVerifierAndSignerTest {
1717

@@ -44,4 +44,30 @@ public void verifierShouldRejectIncorrectlySignedLtiLaunches() throws Exception
4444
assertFalse(result.getSuccess());
4545
}
4646

47+
@Test
48+
public void verifierShouldVerifyCorrectlySignedLtiGetServiceRequests() throws Exception {
49+
50+
String key = "key";
51+
String secret = "secret";
52+
HttpGet ltiServiceGetRequest = new HttpGet(new URI("http://example.com/test"));
53+
54+
signer.sign(ltiServiceGetRequest, key, secret);
55+
LtiVerificationResult result = verifier.verify(new MockHttpGet(ltiServiceGetRequest), secret);
56+
57+
assertTrue(result.getSuccess());
58+
}
59+
60+
@Test
61+
public void verifierShouldRejectIncorrectlySignedLtiGetServiceRequests() throws Exception {
62+
63+
String key = "key";
64+
String secret = "secret";
65+
HttpGet ltiServiceGetRequest = new HttpGet(new URI("http://example.com/test"));
66+
67+
signer.sign(ltiServiceGetRequest, key, secret);
68+
LtiVerificationResult result = verifier.verify(new MockHttpGet(ltiServiceGetRequest), "anotherWrongSecret");
69+
70+
assertFalse(result.getSuccess());
71+
}
72+
4773
}

src/test/java/org/imsglobal/lti/launch/MockHttpGet.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package org.imsglobal.lti.launch;
22

33
import org.apache.http.client.methods.HttpGet;
4-
import org.apache.http.client.methods.HttpPost;
54

65
import java.util.HashMap;
76
import java.util.Map;
87

98
/**
10-
* Created by paul on 8/24/16.
9+
* @author Paul Gray
1110
*/
1211
public class MockHttpGet extends BaseMockHttpServletRequest {
1312

src/test/java/org/imsglobal/lti/launch/MockHttpPost.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.*;
66

77
/**
8-
* Created by paul on 8/24/16.
8+
* @author Paul Gray
99
*/
1010
public class MockHttpPost extends BaseMockHttpServletRequest {
1111

0 commit comments

Comments
 (0)