New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom Auth Query Params (2) #666
Changes from 6 commits
17a5f5d
11c8812
d61aa70
25ae27b
0851c9c
240891e
1c3b5f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Copyright 2016 Google Inc | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using Moq; | ||
using NUnit.Framework; | ||
|
||
using Google.Apis.Auth.OAuth2.Flows; | ||
using Google.Apis.Auth.OAuth2.Requests; | ||
using Google.Apis.Auth.OAuth2.Responses; | ||
using Google.Apis.Http; | ||
using Google.Apis.Util.Store; | ||
|
||
namespace Google.Apis.Auth.OAuth2.Flows | ||
{ | ||
/// <summary>Tests for <see cref="Google.Apis.Auth.OAuth2.Flows.GoogleAuthorizationCodeFlow"/>.</summary> | ||
public class GoogleAuthorizationCodeFlowTests | ||
{ | ||
GoogleAuthorizationCodeFlow.Initializer initializer { get; set; } | ||
List<KeyValuePair<string, string>> userDefinedParams { get; set; } | ||
|
||
[SetUp] | ||
public void GoogleAuthorizationCodeFlowTestSetup() | ||
{ | ||
string revokeTokenUrl = "Revoke Token Url"; | ||
bool? includeGrantedScopes = true; | ||
userDefinedParams = new List<KeyValuePair<string, string>> | ||
{ | ||
new KeyValuePair<string,string>("customParam1","customVal1"), | ||
new KeyValuePair<string,string>("customParam2","customVal2") | ||
}; | ||
|
||
initializer = new GoogleAuthorizationCodeFlow.Initializer() | ||
{ | ||
RevokeTokenUrl = revokeTokenUrl, | ||
IncludeGrantedScopes = includeGrantedScopes, | ||
UserDefinedQueryParams = userDefinedParams, | ||
ClientSecrets = new ClientSecrets() | ||
}; | ||
} | ||
|
||
[Test] | ||
public void ConstructorTest() | ||
{ | ||
var flow = new GoogleAuthorizationCodeFlow(initializer); | ||
|
||
Assert.That(flow.RevokeTokenUrl, Is.EqualTo(initializer.RevokeTokenUrl)); | ||
Assert.That(flow.IncludeGrantedScopes, Is.EqualTo(initializer.IncludeGrantedScopes)); | ||
Assert.That(flow.UserDefinedQueryParams, Is.EqualTo(initializer.UserDefinedQueryParams)); | ||
} | ||
|
||
[Test] | ||
public void CreateAuthorizationCodeRequestTest() | ||
{ | ||
var flow = new GoogleAuthorizationCodeFlow(initializer); | ||
|
||
var request = flow.CreateAuthorizationCodeRequest("TestRedirectUri") as GoogleAuthorizationCodeRequestUrl; | ||
|
||
Assert.AreEqual(request.AccessType, "offline"); | ||
Assert.AreEqual(request.IncludeGrantedScopes, "true"); | ||
Assert.AreEqual(request.UserDefinedQueryParams, userDefinedParams); | ||
Assert.AreEqual(request.RedirectUri, "TestRedirectUri"); | ||
} | ||
|
||
[Test] | ||
public void RevokeTokenAsyncTest() | ||
{ | ||
//TODO | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright 2016 Google Inc | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
using System.Collections.Generic; | ||
|
||
using NUnit.Framework; | ||
|
||
using Google.Apis.Util; | ||
using Google.Apis.Requests; | ||
using Google.Apis.Requests.Parameters; | ||
|
||
namespace Google.Apis.Tests.Apis.Requests | ||
{ | ||
/// <summary>Tests for <see cref="Google.Apis.Requests.Parameters.ParameterUtils"/>.</summary> | ||
[TestFixture] | ||
public class ParameterUtilsTest | ||
{ | ||
private class TestRequestUrl | ||
{ | ||
[Google.Apis.Util.RequestParameterAttribute("first_query_param", Google.Apis.Util.RequestParameterType.Query)] | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
public string FirstParam { get; set; } | ||
|
||
[Google.Apis.Util.RequestParameterAttribute("second_query_param", Google.Apis.Util.RequestParameterType.Query)] | ||
public string SecondParam { get; set; } | ||
|
||
[Google.Apis.Util.RequestParameterAttribute("query_param_attribute_name", Google.Apis.Util.RequestParameterType.UserDefinedQueries)] | ||
public List<KeyValuePair<string, string>> ParamsCollection { get; set; } | ||
|
||
public System.Uri Build() | ||
{ | ||
var builder = new RequestBuilder() | ||
{ | ||
BaseUri = new System.Uri("//revokeTokenUrl") | ||
}; | ||
ParameterUtils.InitParameters(builder, this); | ||
return builder.BuildUri(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void IterateParametersTest() | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
{ | ||
var request = new TestRequestUrl() | ||
{ | ||
FirstParam = "firstOne", | ||
SecondParam = "secondOne", | ||
ParamsCollection = new List<KeyValuePair<string, string>>{ | ||
new KeyValuePair<string,string>("customParam1","customVal1"), | ||
new KeyValuePair<string,string>("customParam2","customVal2") | ||
} | ||
}; | ||
|
||
var result = request.Build().AbsoluteUri; | ||
|
||
//parameter was given a name and a value, so both appear in the uri | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
Assert.That(result, Contains.Substring("first_query_param=firstOne")); | ||
|
||
//parameter was given value only, so the name is the name of the property in lower case | ||
Assert.That(result, Contains.Substring("second_query_param=secondOne")); | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
|
||
//custom parameters are key value pairs representing parameter names and values respectively | ||
Assert.That(result, Contains.Substring("customParam1=customVal1")); | ||
Assert.That(result, Contains.Substring("customParam2=customVal2")); | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
|
||
//assert that the parameter name for the custom parameters does not carry through to the result | ||
Assert.IsFalse(result.Contains("query_param_attribute_name")); | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
} | ||
} | ||
} |
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.