Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1145)

Side by Side Diff: Src/GoogleApis.Auth.Tests/OAuth2/BearerTokenTests.cs

Issue 13972043: Issue 351: Reimplement OAuth2 (Step 3 - Tests, Flows and Credential) (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: minor Created 10 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 Copyright 2013 Google Inc
3
4 Licensed under the Apache License, Version 2.0(the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 using System.Net.Http;
21 using System.Net.Http.Headers;
22 using System.Text;
23
24 using NUnit.Framework;
25
26 namespace Google.Apis.Auth.OAuth2
27 {
28 /// <summary>Tests for <see cref="Google.Apis.Auth.OAuth2.BearerToken"/>.</s ummary>
29 [TestFixture]
30 public class BearerTokenTests
31 {
32 [Test]
33 public void AuthorizationHeaderAccessMethod_Intercept()
34 {
35 var request = new HttpRequestMessage();
36 new BearerToken.AuthorizationHeaderAccessMethod().Intercept(request, "abc");
37 Assert.That(request.Headers.Authorization.ToString(), Is.EqualTo("Be arer abc"));
38 }
39
40 [Test]
41 public void AuthorizationHeaderAccessMethod_InterceptOverride()
42 {
43 var request = new HttpRequestMessage();
44 request.Headers.Authorization = new AuthenticationHeaderValue("a", " 1");
45 new BearerToken.AuthorizationHeaderAccessMethod().Intercept(request, "abc");
46 Assert.That(request.Headers.Authorization.ToString(), Is.EqualTo("Be arer abc"));
47 }
48
49 [Test]
50 public void AuthorizationHeaderAccessMethod_GetAccessToken()
51 {
52 var request = new HttpRequestMessage();
53 request.Headers.Authorization = new AuthenticationHeaderValue("a", " 1");
54 var accessToken = new BearerToken.AuthorizationHeaderAccessMethod(). GetAccessToken(request);
55 Assert.IsNullOrEmpty(accessToken);
56
57 request.Headers.Authorization = new AuthenticationHeaderValue("Beare r", "abc");
58 accessToken = new BearerToken.AuthorizationHeaderAccessMethod().GetA ccessToken(request);
59 Assert.That(accessToken, Is.EqualTo("abc"));
60 }
61
62 [Test]
63 public void QueryParameterAccessMethod_Intercept()
64 {
65 var request = new HttpRequestMessage(HttpMethod.Get, new Uri("https: //sample.com/path"));
66 new BearerToken.QueryParameterAccessMethod().Intercept(request, "abc ");
67 Assert.That(request.RequestUri, Is.EqualTo(new Uri("https://sample.c om/path?access_token=abc")));
68 }
69
70 [Test]
71 public void QueryParameterAccessMethod_Intercept_WithQueryParameters()
72 {
73 var request = new HttpRequestMessage(HttpMethod.Get, new Uri("https: //sample.com/path?a=1"));
74 new BearerToken.QueryParameterAccessMethod().Intercept(request, "abc ");
75 Assert.That(request.RequestUri, Is.EqualTo(new Uri("https://sample.c om/path?a=1&access_token=abc")));
76 }
77
78 [Test]
79 public void QueryParameterAccessMethod_GetAccessToken()
80 {
81 // No query parameter at all.
82 var request = new HttpRequestMessage(HttpMethod.Get, new Uri("https: //sample.com"));
83 var accessToken = new BearerToken.QueryParameterAccessMethod().GetAc cessToken(request);
84 Assert.IsNullOrEmpty(accessToken);
85
86 // Different query parameter.
87 request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://sa mple.com?a=1"));
88 accessToken = new BearerToken.QueryParameterAccessMethod().GetAccess Token(request);
89 Assert.IsNullOrEmpty(accessToken);
90
91 // One query parameter and it's access_token.
92 request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://sa mple.com?a=1&access_token=abc"));
93 accessToken = new BearerToken.QueryParameterAccessMethod().GetAccess Token(request);
94 Assert.That(accessToken, Is.EqualTo("abc"));
95
96 // 2 query parameters and one of them is access_token.
97 request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://sa mple.com?access_token=abc"));
98 accessToken = new BearerToken.QueryParameterAccessMethod().GetAccess Token(request);
99 Assert.That(accessToken, Is.EqualTo("abc"));
100 }
101 }
102 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b