1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.amber.oauth2.common.parameters;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.apache.amber.oauth2.common.OAuth;
28 import org.apache.amber.oauth2.common.message.OAuthResponse;
29 import org.junit.Assert;
30 import org.junit.Test;
31
32
33
34
35
36
37 public class WWWAuthHeaderParametersApplierTest {
38
39 @Test
40 public void testApplyOAuthParameters() throws Exception {
41
42 Map<String, Object> params = new HashMap<String, Object>();
43 params.put("error", "invalid_token");
44 params.put("error_uri", "http://www.example.com/error");
45 params.put("scope", "s1 s2 s3");
46 params.put("empty_param", "");
47 params.put("null_param", null);
48 params.put("", "some_value");
49 params.put(null, "some_value");
50
51 OAuthResponse res = OAuthResponse.status(200).location("").buildQueryMessage();
52
53 OAuthParametersApplier applier = new WWWAuthHeaderParametersApplier();
54 res = (OAuthResponse)applier.applyOAuthParameters(res, params);
55 Assert.assertNotNull(res);
56 String header = res.getHeader(OAuth.HeaderType.WWW_AUTHENTICATE);
57 Assert.assertNotNull(header);
58 Assert.assertEquals(OAuth.OAUTH_HEADER_NAME
59 + " scope=\"s1 s2 s3\",error_uri=\"http://www.example.com/error\",error=\"invalid_token\"",
60 header);
61
62
63 }
64
65 }