@@ -9,23 +9,23 @@ namespace EntityDb.Mvc.Tests.Agents
9
9
public class HttpContextAgentSignatureTests
10
10
{
11
11
[ Fact ]
12
- public void GivenNoDoNotRecordHeaders_WhenHttpContextHasSingleHeader_ThenAgentSignatureHasSingleHeader ( )
12
+ public void GivenNoRedactedHeaders_WhenHttpContextHasHeader_ThenAgentSignatureHasHeaderValue ( )
13
13
{
14
14
// ARRANGE
15
15
16
- const string RecordHeaderName = nameof ( RecordHeaderName ) ;
17
- const string RecordHeaderValue = nameof ( RecordHeaderValue ) ;
16
+ const string HeaderName = nameof ( HeaderName ) ;
17
+ const string HeaderValue = nameof ( HeaderValue ) ;
18
18
19
19
var httpContextAgentOptions = new HttpContextAgentSignatureOptions
20
20
{
21
- DoNotRecordHeaders = Array . Empty < string > ( )
21
+ RedactedHeaders = Array . Empty < string > ( )
22
22
} ;
23
23
24
24
var httpContext = HttpContextSeeder . CreateHttpContext ( new HttpContextSeederOptions
25
25
{
26
26
Headers = new ( )
27
27
{
28
- [ RecordHeaderName ] = new [ ] { RecordHeaderValue }
28
+ [ HeaderName ] = new [ ] { HeaderValue }
29
29
}
30
30
} ) ;
31
31
@@ -36,28 +36,31 @@ public void GivenNoDoNotRecordHeaders_WhenHttpContextHasSingleHeader_ThenAgentSi
36
36
// ASSERT
37
37
38
38
agentSignature . Request . Headers . Length . ShouldBe ( 1 ) ;
39
- agentSignature . Request . Headers [ 0 ] . Name . ShouldBe ( RecordHeaderName ) ;
39
+ agentSignature . Request . Headers [ 0 ] . Name . ShouldBe ( HeaderName ) ;
40
40
agentSignature . Request . Headers [ 0 ] . Values . Length . ShouldBe ( 1 ) ;
41
- agentSignature . Request . Headers [ 0 ] . Values [ 0 ] . ShouldBe ( RecordHeaderValue ) ;
41
+ agentSignature . Request . Headers [ 0 ] . Values [ 0 ] . ShouldBe ( HeaderValue ) ;
42
42
}
43
43
44
44
[ Fact ]
45
- public void GivenDoNotRecordHeader_WhenHttpContextContainsOnlyThatHeader_ThenAgentSignatureHasNoHeaders ( )
45
+ public void GivenRedactedHeader_WhenHttpContextContainsOnlyThatHeader_ThenAgentSignatureHasRedactedHeader ( )
46
46
{
47
47
// ARRANGE
48
48
49
- const string DoNotRecordHeader = nameof ( DoNotRecordHeader ) ;
49
+ const string HeaderName = nameof ( HeaderName ) ;
50
+ const string HeaderValue = nameof ( HeaderValue ) ;
51
+ const string RedactedValue = nameof ( RedactedValue ) ;
50
52
51
53
var httpContextAgentOptions = new HttpContextAgentSignatureOptions
52
54
{
53
- DoNotRecordHeaders = new [ ] { DoNotRecordHeader }
55
+ RedactedHeaders = new [ ] { HeaderName } ,
56
+ RedactedValue = RedactedValue ,
54
57
} ;
55
58
56
59
var httpContext = HttpContextSeeder . CreateHttpContext ( new HttpContextSeederOptions
57
60
{
58
61
Headers = new ( )
59
62
{
60
- [ DoNotRecordHeader ] = Array . Empty < string > ( )
63
+ [ HeaderName ] = new [ ] { HeaderValue }
61
64
}
62
65
} ) ;
63
66
@@ -67,7 +70,78 @@ public void GivenDoNotRecordHeader_WhenHttpContextContainsOnlyThatHeader_ThenAge
67
70
68
71
// ASSERT
69
72
70
- agentSignature . Request . Headers . ShouldBeEmpty ( ) ;
73
+ agentSignature . Request . Headers . Length . ShouldBe ( 1 ) ;
74
+ agentSignature . Request . Headers [ 0 ] . Name . ShouldBe ( HeaderName ) ;
75
+ agentSignature . Request . Headers [ 0 ] . Values . Length . ShouldBe ( 1 ) ;
76
+ agentSignature . Request . Headers [ 0 ] . Values [ 0 ] . ShouldBe ( RedactedValue ) ;
77
+ }
78
+
79
+ [ Fact ]
80
+ public void GivenNoRedactedQueryStringParams_WhenHttpContextHasQueryStringParam_ThenAgentSignatureHasQueryStringParamValue ( )
81
+ {
82
+ // ARRANGE
83
+
84
+ const string QueryStringParamName = nameof ( QueryStringParamName ) ;
85
+ const string QueryStringParamValue = nameof ( QueryStringParamValue ) ;
86
+
87
+ var httpContextAgentOptions = new HttpContextAgentSignatureOptions
88
+ {
89
+ RedactedQueryStringParams = Array . Empty < string > ( )
90
+ } ;
91
+
92
+ var httpContext = HttpContextSeeder . CreateHttpContext ( new HttpContextSeederOptions
93
+ {
94
+ QueryStringParams = new ( )
95
+ {
96
+ [ QueryStringParamName ] = new [ ] { QueryStringParamValue }
97
+ }
98
+ } ) ;
99
+
100
+ // ACT
101
+
102
+ var agentSignature = HttpContextAgentSignature . GetSnapshot ( httpContext , httpContextAgentOptions ) ;
103
+
104
+ // ASSERT
105
+
106
+ agentSignature . Request . QueryStringParams . Length . ShouldBe ( 1 ) ;
107
+ agentSignature . Request . QueryStringParams [ 0 ] . Name . ShouldBe ( QueryStringParamName ) ;
108
+ agentSignature . Request . QueryStringParams [ 0 ] . Values . Length . ShouldBe ( 1 ) ;
109
+ agentSignature . Request . QueryStringParams [ 0 ] . Values [ 0 ] . ShouldBe ( QueryStringParamValue ) ;
110
+ }
111
+
112
+ [ Fact ]
113
+ public void GivenRedactedQueryStringParam_WhenHttpContextContainsOnlyThatQueryStringParam_ThenAgentSignatureHasRedactedQueryStringParams ( )
114
+ {
115
+ // ARRANGE
116
+
117
+ const string QueryStringParamName = nameof ( QueryStringParamName ) ;
118
+ const string QueryStringParamValue = nameof ( QueryStringParamValue ) ;
119
+ const string RedactedValue = nameof ( RedactedValue ) ;
120
+
121
+ var httpContextAgentOptions = new HttpContextAgentSignatureOptions
122
+ {
123
+ RedactedQueryStringParams = new [ ] { QueryStringParamName } ,
124
+ RedactedValue = RedactedValue ,
125
+ } ;
126
+
127
+ var httpContext = HttpContextSeeder . CreateHttpContext ( new HttpContextSeederOptions
128
+ {
129
+ QueryStringParams = new ( )
130
+ {
131
+ [ QueryStringParamName ] = new [ ] { QueryStringParamValue }
132
+ }
133
+ } ) ;
134
+
135
+ // ACT
136
+
137
+ var agentSignature = HttpContextAgentSignature . GetSnapshot ( httpContext , httpContextAgentOptions ) ;
138
+
139
+ // ASSERT
140
+
141
+ agentSignature . Request . QueryStringParams . Length . ShouldBe ( 1 ) ;
142
+ agentSignature . Request . QueryStringParams [ 0 ] . Name . ShouldBe ( QueryStringParamName ) ;
143
+ agentSignature . Request . QueryStringParams [ 0 ] . Values . Length . ShouldBe ( 1 ) ;
144
+ agentSignature . Request . QueryStringParams [ 0 ] . Values [ 0 ] . ShouldBe ( RedactedValue ) ;
71
145
}
72
146
}
73
147
}
0 commit comments