Repository navigation
Expand file tree
/
Copy pathOAuthChallengePropertiesTest.cs
More file actions
149 lines (130 loc) · 5.14 KB
/
Copy pathOAuthChallengePropertiesTest.cs
File metadata and controls
149 lines (130 loc) · 5.14 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
using System;
using Microsoft.AspNetCore.Authentication.Google;
using Microsoft.AspNetCore.Authentication.OAuth;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Xunit;
namespace Microsoft.AspNetCore.Authentication.Test
{
public class OAuthChallengePropertiesTest
{
[Fact]
public void ScopeProperty()
{
var properties = new OAuthChallengeProperties
{
Scope = new string[] { "foo", "bar" }
};
Assert.Equal(new string[] { "foo", "bar" }, properties.Scope);
Assert.Equal(new string[] { "foo", "bar" }, properties.Parameters["scope"]);
}
[Fact]
public void ScopeProperty_NullValue()
{
var properties = new OAuthChallengeProperties();
properties.Parameters["scope"] = new string[] { "foo", "bar" };
Assert.Equal(new string[] { "foo", "bar" }, properties.Scope);
properties.Scope = null;
Assert.Null(properties.Scope);
}
[Fact]
public void SetScope()
{
var properties = new OAuthChallengeProperties();
properties.SetScope("foo", "bar");
Assert.Equal(new string[] { "foo", "bar" }, properties.Scope);
Assert.Equal(new string[] { "foo", "bar" }, properties.Parameters["scope"]);
}
[Fact]
public void OidcMaxAge()
{
var properties = new OpenIdConnectChallengeProperties()
{
MaxAge = TimeSpan.FromSeconds(200)
};
Assert.Equal(TimeSpan.FromSeconds(200), properties.MaxAge);
}
[Fact]
public void OidcMaxAge_NullValue()
{
var properties = new OpenIdConnectChallengeProperties();
properties.Parameters["max_age"] = TimeSpan.FromSeconds(500);
Assert.Equal(TimeSpan.FromSeconds(500), properties.MaxAge);
properties.MaxAge = null;
Assert.Null(properties.MaxAge);
}
[Fact]
public void OidcPrompt()
{
var properties = new OpenIdConnectChallengeProperties()
{
Prompt = "login"
};
Assert.Equal("login", properties.Prompt);
Assert.Equal("login", properties.Parameters["prompt"]);
}
[Fact]
public void OidcPrompt_NullValue()
{
var properties = new OpenIdConnectChallengeProperties();
properties.Parameters["prompt"] = "consent";
Assert.Equal("consent", properties.Prompt);
properties.Prompt = null;
Assert.Null(properties.Prompt);
}
[Fact]
public void GoogleProperties()
{
var properties = new GoogleChallengeProperties()
{
AccessType = "offline",
ApprovalPrompt = "force",
LoginHint = "test@example.com",
Prompt = "login",
};
Assert.Equal("offline", properties.AccessType);
Assert.Equal("offline", properties.Parameters["access_type"]);
Assert.Equal("force", properties.ApprovalPrompt);
Assert.Equal("force", properties.Parameters["approval_prompt"]);
Assert.Equal("test@example.com", properties.LoginHint);
Assert.Equal("test@example.com", properties.Parameters["login_hint"]);
Assert.Equal("login", properties.Prompt);
Assert.Equal("login", properties.Parameters["prompt"]);
}
[Fact]
public void GoogleProperties_NullValues()
{
var properties = new GoogleChallengeProperties();
properties.Parameters["access_type"] = "offline";
properties.Parameters["approval_prompt"] = "force";
properties.Parameters["login_hint"] = "test@example.com";
properties.Parameters["prompt"] = "login";
Assert.Equal("offline", properties.AccessType);
Assert.Equal("force", properties.ApprovalPrompt);
Assert.Equal("test@example.com", properties.LoginHint);
Assert.Equal("login", properties.Prompt);
properties.AccessType = null;
Assert.Null(properties.AccessType);
properties.ApprovalPrompt = null;
Assert.Null(properties.ApprovalPrompt);
properties.LoginHint = null;
Assert.Null(properties.LoginHint);
properties.Prompt = null;
Assert.Null(properties.Prompt);
}
[Fact]
public void GoogleIncludeGrantedScopes()
{
var properties = new GoogleChallengeProperties()
{
IncludeGrantedScopes = true
};
Assert.True(properties.IncludeGrantedScopes);
Assert.Equal(true, properties.Parameters["include_granted_scopes"]);
properties.IncludeGrantedScopes = false;
Assert.False(properties.IncludeGrantedScopes);
Assert.Equal(false, properties.Parameters["include_granted_scopes"]);
properties.IncludeGrantedScopes = null;
Assert.Null(properties.IncludeGrantedScopes);
}
}
}