1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
+ using System . Runtime . InteropServices ;
4
5
using System . Text ;
5
6
using Xunit ;
6
7
using System . Globalization ;
8
+ using Xunit . Extensions ;
7
9
8
10
namespace RestSharp . Tests {
9
11
public class RestRequestTests {
@@ -17,5 +19,67 @@ public void Can_Add_Object_With_IntegerArray_property() {
17
19
var request = new RestRequest ( ) ;
18
20
request . AddObject ( new { Items = new int [ ] { 2 , 3 , 4 } } ) ;
19
21
}
22
+
23
+ [ Fact ]
24
+ public void Cannot_Set_Empty_Host_Header ( )
25
+ {
26
+ var request = new RestRequest ( ) ;
27
+
28
+ var exception = Assert . Throws < ArgumentException > ( ( ) => request . AddHeader ( "Host" , string . Empty ) ) ;
29
+ Assert . Equal ( "value" , exception . ParamName ) ;
30
+ }
31
+
32
+ [ Fact ]
33
+ public void Cannot_Set_Too_Long_Host_Header ( )
34
+ {
35
+ var request = new RestRequest ( ) ;
36
+
37
+ var exception = Assert . Throws < ArgumentException > ( ( ) => request . AddHeader ( "Host" , new string ( 'a' , 256 ) ) ) ;
38
+ Assert . Equal ( "value" , exception . ParamName ) ;
39
+ }
40
+
41
+ [ Theory ]
42
+ [ InlineData ( "http://localhost" ) ]
43
+ [ InlineData ( "hostname 1234" ) ]
44
+ [ InlineData ( "-leading.hyphen.not.allowed" ) ]
45
+ [ InlineData ( "not.allowéd" ) ]
46
+ [ InlineData ( "bad:port" ) ]
47
+ [ InlineData ( " no.leading.white-space" ) ]
48
+ [ InlineData ( "no.trailing.white-space " ) ]
49
+ [ InlineData ( ".leading.dot.not.allowed" ) ]
50
+ [ InlineData ( "trailing.dot.not.allowed." ) ]
51
+ [ InlineData ( "double.dots..not.allowed" ) ]
52
+ [ InlineData ( "." ) ]
53
+ [ InlineData ( ".:2345" ) ]
54
+ [ InlineData ( ":5678" ) ]
55
+ [ InlineData ( "1234567890123456789012345678901234567890123456789012345678901234.too.long.label" ) ]
56
+ public void Cannot_Set_Invalid_Host_Header ( string value )
57
+ {
58
+ var request = new RestRequest ( ) ;
59
+
60
+ var exception = Assert . Throws < ArgumentException > ( ( ) => request . AddHeader ( "Host" , value ) ) ;
61
+ Assert . Equal ( "value" , exception . ParamName ) ;
62
+ }
63
+
64
+ [ Theory ]
65
+ [ InlineData ( "localhost" ) ]
66
+ [ InlineData ( "localhost:1234" ) ]
67
+ [ InlineData ( "host.local" ) ]
68
+ [ InlineData ( "anotherhost.local:2345" ) ]
69
+ [ InlineData ( "www.w3.org" ) ]
70
+ [ InlineData ( "www.w3.org:3456" ) ]
71
+ [ InlineData ( "8.8.8.8" ) ]
72
+ [ InlineData ( "a.1.b.2" ) ]
73
+ [ InlineData ( "10.20.30.40:1234" ) ]
74
+ [ InlineData ( "0host" ) ]
75
+ [ InlineData ( "hypenated-hostname" ) ]
76
+ [ InlineData ( "multi--hyphens" ) ]
77
+ [ InlineData ( "123456789012345678901234567890123456789012345678901234567890123" ) ]
78
+ public void Can_Set_Valid_Host_Header ( string value )
79
+ {
80
+ var request = new RestRequest ( ) ;
81
+
82
+ Assert . DoesNotThrow ( ( ) => request . AddHeader ( "Host" , value ) ) ;
83
+ }
20
84
}
21
85
}
0 commit comments