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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
17a5f5d
First new commit, still some details to iron out.
squid808 11c8812
Fixed spelling error, formatting, logger assignment and added new con…
squid808 d61aa70
Improved type detection of custom param collection, updated unit test…
squid808 25ae27b
Fixed missing constructor logic to set UserDefinedQueryParams
squid808 0851c9c
Added 2/3 of GoogleAuthorizationCodeFlowTests, updated param info on …
squid808 240891e
Removed nameless constructor for RequestParameterAttribute, adjusted …
squid808 1c3b5f8
Adjusted comments and formatting.
squid808 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
Src/Support/GoogleApis.Auth.Tests/OAuth2/Flows/GoogleAuthorizationCodeFlowTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
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"); | ||
} | ||
|
||
//TODO(squid808): Add tests for RevokeToken. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
Src/Support/GoogleApis.Tests/Apis/Requests/Parameters/ParameterUtilsTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
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)] | ||
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; | ||
|
||
//Parametera were given a name and a value, so both appear in the URI. | ||
Assert.That(result, Contains.Substring("first_query_param=firstOne")); | ||
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. |
||
|
||
//The parameter name for the custom parameters does not carry through to the resulting URI. | ||
Assert.IsFalse(result.Contains("query_param_attribute_name")); | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.