forked from scribejava/scribejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOAuth1AccessTokenExtractorTest.java
More file actions
82 lines (67 loc) · 3.2 KB
/
Copy pathOAuth1AccessTokenExtractorTest.java
File metadata and controls
82 lines (67 loc) · 3.2 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
78
79
80
81
82
package com.github.scribejava.core.extractors;
import com.github.scribejava.core.model.Response;
import org.junit.Before;
import org.junit.Test;
import com.github.scribejava.core.exceptions.OAuthException;
import com.github.scribejava.core.model.OAuth1Token;
import java.io.IOException;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
public class OAuth1AccessTokenExtractorTest {
private OAuth1AccessTokenExtractor extractor;
@Before
public void setUp() {
extractor = OAuth1AccessTokenExtractor.instance();
}
@Test
public void shouldExtractTokenFromOAuthStandardResponse() throws IOException {
final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03";
final OAuth1Token extracted = extractor.extract(ok(response));
assertEquals("hh5s93j4hdidpola", extracted.getToken());
assertEquals("hdhd0244k9j7ao03", extracted.getTokenSecret());
}
@Test
public void shouldExtractTokenFromInvertedOAuthStandardResponse() throws IOException {
final String response = "oauth_token_secret=hh5s93j4hdidpola&oauth_token=hdhd0244k9j7ao03";
final OAuth1Token extracted = extractor.extract(ok(response));
assertEquals("hh5s93j4hdidpola", extracted.getTokenSecret());
assertEquals("hdhd0244k9j7ao03", extracted.getToken());
}
@Test
public void shouldExtractTokenFromResponseWithCallbackConfirmed() throws IOException {
final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03"
+ "&callback_confirmed=true";
final OAuth1Token extracted = extractor.extract(ok(response));
assertEquals("hh5s93j4hdidpola", extracted.getToken());
assertEquals("hdhd0244k9j7ao03", extracted.getTokenSecret());
}
@Test
public void shouldExtractTokenWithEmptySecret() throws IOException {
final String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=";
final OAuth1Token extracted = extractor.extract(ok(response));
assertEquals("hh5s93j4hdidpola", extracted.getToken());
assertEquals("", extracted.getTokenSecret());
}
@Test(expected = OAuthException.class)
public void shouldThrowExceptionIfTokenIsAbsent() throws IOException {
final String response = "oauth_secret=hh5s93j4hdidpola&callback_confirmed=true";
extractor.extract(ok(response));
}
@Test(expected = OAuthException.class)
public void shouldThrowExceptionIfSecretIsAbsent() throws IOException {
final String response = "oauth_token=hh5s93j4hdidpola&callback_confirmed=true";
extractor.extract(ok(response));
}
@Test(expected = IllegalArgumentException.class)
public void shouldThrowExceptionIfResponseIsNull() throws IOException {
extractor.extract(ok(null));
}
@Test(expected = IllegalArgumentException.class)
public void shouldThrowExceptionIfResponseIsEmptyString() throws IOException {
final String response = "";
extractor.extract(ok(response));
}
private static Response ok(String body) {
return new Response(200, /* message */ null, /* headers */ Collections.<String, String>emptyMap(), body);
}
}