forked from scribejava/scribejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeaderExtractorTest.java
More file actions
56 lines (48 loc) · 2.08 KB
/
Copy pathHeaderExtractorTest.java
File metadata and controls
56 lines (48 loc) · 2.08 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
package com.github.scribejava.core.extractors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import com.github.scribejava.core.exceptions.OAuthParametersMissingException;
import com.github.scribejava.core.model.OAuthRequest;
import com.github.scribejava.core.model.Verb;
import com.github.scribejava.core.ObjectMother;
public class HeaderExtractorTest {
private HeaderExtractorImpl extractor;
private OAuthRequest request;
@Before
public void setUp() {
request = ObjectMother.createSampleOAuthRequest();
extractor = new HeaderExtractorImpl();
}
@Test
public void shouldExtractStandardHeader() {
final String header = extractor.extract(request);
final String oauth = "OAuth ";
final String callback = "oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\"";
final String signature = "oauth_signature=\"OAuth-Signature\"";
final String key = "oauth_consumer_key=\"AS%23%24%5E%2A%40%26\"";
final String timestamp = "oauth_timestamp=\"123456\"";
assertTrue(header.startsWith(oauth));
assertTrue(header.contains(callback));
assertTrue(header.contains(signature));
assertTrue(header.contains(key));
assertTrue(header.contains(timestamp));
// Assert that header only contains the checked elements above and nothing else
assertEquals(", , , ",
header.replaceFirst(oauth, "")
.replaceFirst(callback, "")
.replaceFirst(signature, "")
.replaceFirst(key, "")
.replaceFirst(timestamp, ""));
}
@Test(expected = IllegalArgumentException.class)
public void shouldExceptionIfRequestIsNull() {
extractor.extract(null);
}
@Test(expected = OAuthParametersMissingException.class)
public void shouldExceptionIfRequestHasNoOAuthParams() {
final OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com");
extractor.extract(emptyRequest);
}
}