11// Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
4+ using System ;
45using System . Linq ;
56using System . Net ;
67using System . Net . Http ;
78using System . Threading . Tasks ;
89using Microsoft . AspNetCore . Antiforgery ;
10+ using Microsoft . Extensions . Primitives ;
911using Microsoft . Net . Http . Headers ;
1012using Xunit ;
1113
@@ -29,15 +31,15 @@ public async Task ItemsPage_SetsXSRFTokens()
2931 // Assert
3032 var setCookieHeaderValue = RetrieveAntiforgeryCookie ( response ) ;
3133 Assert . NotNull ( setCookieHeaderValue ) ;
32- Assert . False ( string . IsNullOrEmpty ( setCookieHeaderValue . Value ) ) ;
33- Assert . Null ( setCookieHeaderValue . Domain ) ;
34+ Assert . False ( StringSegment . IsNullOrEmpty ( setCookieHeaderValue . Value ) ) ;
35+ Assert . Null ( setCookieHeaderValue . Domain . Value ) ;
3436 Assert . Equal ( "/" , setCookieHeaderValue . Path ) ;
3537 Assert . False ( setCookieHeaderValue . Secure ) ;
3638
3739 setCookieHeaderValue = RetrieveAntiforgeryToken ( response ) ;
3840 Assert . NotNull ( setCookieHeaderValue ) ;
39- Assert . False ( string . IsNullOrEmpty ( setCookieHeaderValue . Value ) ) ;
40- Assert . Null ( setCookieHeaderValue . Domain ) ;
41+ Assert . False ( StringSegment . IsNullOrEmpty ( setCookieHeaderValue . Value ) ) ;
42+ Assert . Null ( setCookieHeaderValue . Domain . Value ) ;
4143 Assert . Equal ( "/" , setCookieHeaderValue . Path ) ;
4244 Assert . False ( setCookieHeaderValue . Secure ) ;
4345 }
@@ -73,7 +75,7 @@ public async Task PostItem_XSRFWorks()
7375 var httpRequestMessage = new HttpRequestMessage ( HttpMethod . Post , "http://localhost/api/items" ) ;
7476
7577 httpRequestMessage . Headers . Add ( "Cookie" , $ "{ cookie . Name } ={ cookie . Value } ") ;
76- httpRequestMessage . Headers . Add ( "X-XSRF-TOKEN" , token . Value ) ;
78+ httpRequestMessage . Headers . Add ( "X-XSRF-TOKEN" , token . Value . Value ) ;
7779
7880 // Act
7981 var response = await Client . SendAsync ( httpRequestMessage ) ;
@@ -94,7 +96,7 @@ private static SetCookieHeaderValue RetrieveAntiforgeryCookie(HttpResponseMessag
9496 {
9597 return response . Headers . GetValues ( HeaderNames . SetCookie )
9698 . Select ( setCookieValue => SetCookieHeaderValue . Parse ( setCookieValue ) )
97- . Where ( setCookieHeaderValue => setCookieHeaderValue . Name . StartsWith ( ".AspNetCore.Antiforgery." ) )
99+ . Where ( setCookieHeaderValue => setCookieHeaderValue . Name . StartsWith ( ".AspNetCore.Antiforgery." , StringComparison . Ordinal ) )
98100 . FirstOrDefault ( ) ;
99101 }
100102 }
0 commit comments