@@ -53,11 +53,30 @@ public async Task anonymous_call_to_user_token_requirement_route_should_fail()
53
53
}
54
54
55
55
[ Fact ]
56
- public async Task authenticated_GET_should_forward_user_to_api ( )
56
+ public async Task anonymous_call_to_optional_user_token_route_should_succeed ( )
57
+ {
58
+ var req = new HttpRequestMessage ( HttpMethod . Get , BffHost . Url ( "/api_optional_user/test" ) ) ;
59
+ req . Headers . Add ( "x-csrf" , "1" ) ;
60
+ var response = await BffHost . BrowserClient . SendAsync ( req ) ;
61
+
62
+ response . IsSuccessStatusCode . Should ( ) . BeTrue ( ) ;
63
+ response . Content . Headers . ContentType . MediaType . Should ( ) . Be ( "application/json" ) ;
64
+ var json = await response . Content . ReadAsStringAsync ( ) ;
65
+ var apiResult = JsonSerializer . Deserialize < ApiResponse > ( json ) ;
66
+ apiResult . Method . Should ( ) . Be ( "GET" ) ;
67
+ apiResult . Path . Should ( ) . Be ( "/api_optional_user/test" ) ;
68
+ apiResult . Sub . Should ( ) . BeNull ( ) ;
69
+ apiResult . ClientId . Should ( ) . BeNull ( ) ;
70
+ }
71
+
72
+ [ Theory ]
73
+ [ InlineData ( "/api_user/test" ) ]
74
+ [ InlineData ( "/api_optional_user/test" ) ]
75
+ public async Task authenticated_GET_should_forward_user_to_api ( string route )
57
76
{
58
77
await BffHost . BffLoginAsync ( "alice" ) ;
59
78
60
- var req = new HttpRequestMessage ( HttpMethod . Get , BffHost . Url ( "/api_user/test" ) ) ;
79
+ var req = new HttpRequestMessage ( HttpMethod . Get , BffHost . Url ( route ) ) ;
61
80
req . Headers . Add ( "x-csrf" , "1" ) ;
62
81
var response = await BffHost . BrowserClient . SendAsync ( req ) ;
63
82
@@ -66,17 +85,19 @@ public async Task authenticated_GET_should_forward_user_to_api()
66
85
var json = await response . Content . ReadAsStringAsync ( ) ;
67
86
var apiResult = JsonSerializer . Deserialize < ApiResponse > ( json ) ;
68
87
apiResult . Method . Should ( ) . Be ( "GET" ) ;
69
- apiResult . Path . Should ( ) . Be ( "/api_user/test" ) ;
88
+ apiResult . Path . Should ( ) . Be ( route ) ;
70
89
apiResult . Sub . Should ( ) . Be ( "alice" ) ;
71
90
apiResult . ClientId . Should ( ) . Be ( "spa" ) ;
72
91
}
73
92
74
- [ Fact ]
75
- public async Task authenticated_PUT_should_forward_user_to_api ( )
93
+ [ Theory ]
94
+ [ InlineData ( "/api_user/test" ) ]
95
+ [ InlineData ( "/api_optional_user/test" ) ]
96
+ public async Task authenticated_PUT_should_forward_user_to_api ( string route )
76
97
{
77
98
await BffHost . BffLoginAsync ( "alice" ) ;
78
99
79
- var req = new HttpRequestMessage ( HttpMethod . Put , BffHost . Url ( "/api_user/test" ) ) ;
100
+ var req = new HttpRequestMessage ( HttpMethod . Put , BffHost . Url ( route ) ) ;
80
101
req . Headers . Add ( "x-csrf" , "1" ) ;
81
102
var response = await BffHost . BrowserClient . SendAsync ( req ) ;
82
103
@@ -85,17 +106,19 @@ public async Task authenticated_PUT_should_forward_user_to_api()
85
106
var json = await response . Content . ReadAsStringAsync ( ) ;
86
107
var apiResult = JsonSerializer . Deserialize < ApiResponse > ( json ) ;
87
108
apiResult . Method . Should ( ) . Be ( "PUT" ) ;
88
- apiResult . Path . Should ( ) . Be ( "/api_user/test" ) ;
109
+ apiResult . Path . Should ( ) . Be ( route ) ;
89
110
apiResult . Sub . Should ( ) . Be ( "alice" ) ;
90
111
apiResult . ClientId . Should ( ) . Be ( "spa" ) ;
91
112
}
92
-
93
- [ Fact ]
94
- public async Task authenticated_POST_should_forward_user_to_api ( )
113
+
114
+ [ Theory ]
115
+ [ InlineData ( "/api_user/test" ) ]
116
+ [ InlineData ( "/api_optional_user/test" ) ]
117
+ public async Task authenticated_POST_should_forward_user_to_api ( string route )
95
118
{
96
119
await BffHost . BffLoginAsync ( "alice" ) ;
97
120
98
- var req = new HttpRequestMessage ( HttpMethod . Post , BffHost . Url ( "/api_user/test" ) ) ;
121
+ var req = new HttpRequestMessage ( HttpMethod . Post , BffHost . Url ( route ) ) ;
99
122
req . Headers . Add ( "x-csrf" , "1" ) ;
100
123
var response = await BffHost . BrowserClient . SendAsync ( req ) ;
101
124
@@ -104,7 +127,7 @@ public async Task authenticated_POST_should_forward_user_to_api()
104
127
var json = await response . Content . ReadAsStringAsync ( ) ;
105
128
var apiResult = JsonSerializer . Deserialize < ApiResponse > ( json ) ;
106
129
apiResult . Method . Should ( ) . Be ( "POST" ) ;
107
- apiResult . Path . Should ( ) . Be ( "/api_user/test" ) ;
130
+ apiResult . Path . Should ( ) . Be ( route ) ;
108
131
apiResult . Sub . Should ( ) . Be ( "alice" ) ;
109
132
apiResult . ClientId . Should ( ) . Be ( "spa" ) ;
110
133
}
@@ -189,5 +212,14 @@ public async Task response_status_403_from_remote_endpoint_should_return_403_fro
189
212
190
213
response . StatusCode . Should ( ) . Be ( HttpStatusCode . Forbidden ) ;
191
214
}
215
+
216
+ [ Fact ]
217
+ public async Task invalid_configuration_of_routes_should_return_500 ( )
218
+ {
219
+ var req = new HttpRequestMessage ( HttpMethod . Get , BffHost . Url ( "/api_invalid/test" ) ) ;
220
+ var response = await BffHost . BrowserClient . SendAsync ( req ) ;
221
+
222
+ response . StatusCode . Should ( ) . Be ( HttpStatusCode . InternalServerError ) ;
223
+ }
192
224
}
193
225
}
0 commit comments