diff options
Diffstat (limited to 'mcs/class/System')
-rw-r--r-- | mcs/class/System/Test/System.Net/ChangeLog | 4 | ||||
-rw-r--r-- | mcs/class/System/Test/System.Net/WebHeaderCollectionTest.cs | 152 |
2 files changed, 156 insertions, 0 deletions
diff --git a/mcs/class/System/Test/System.Net/ChangeLog b/mcs/class/System/Test/System.Net/ChangeLog index b636565ed11..9f6ddd3754c 100644 --- a/mcs/class/System/Test/System.Net/ChangeLog +++ b/mcs/class/System/Test/System.Net/ChangeLog @@ -1,5 +1,9 @@ 2009-07-22 Gonzalo Paniagua Javier <gonzalo@novell.com> + * WebHeaderCollectionTest.cs: test for allowed characters in headers. + +2009-07-22 Gonzalo Paniagua Javier <gonzalo@novell.com> + * WebHeaderCollectionTest.cs: test for 2.0 IsRestricted(). 2009-07-09 Gonzalo Paniagua Javier <gonzalo@novell.com> diff --git a/mcs/class/System/Test/System.Net/WebHeaderCollectionTest.cs b/mcs/class/System/Test/System.Net/WebHeaderCollectionTest.cs index a840997db29..1bc8b4dbea7 100644 --- a/mcs/class/System/Test/System.Net/WebHeaderCollectionTest.cs +++ b/mcs/class/System/Test/System.Net/WebHeaderCollectionTest.cs @@ -377,7 +377,159 @@ namespace MonoTests.System.Net #endif }; + [Test] + public void IsRestricted_InvalidChars_1 () + { + // Not allowed: + // 0-32 + // 34 + // 39-41 + // 44 + // 47 + // 91-93 + // 123 + // 125 + // >= 127 + int [] singles = new int [] { 34, 44, 47, 123, 125 }; + foreach (int single in singles) { + try { + WebHeaderCollection.IsRestricted (new string ((char) single, 1)); + Assert.Fail (String.Format ("{0}: {1}", single, (char) single)); + } catch (ArgumentException) { + } + } + for (int i = 0; i <= 32; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1)); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + for (int i = 39; i <= 41; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1)); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + for (int i = 91; i <= 93; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1)); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + for (int i = 127; i <= 255; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1)); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + } #if NET_2_0 + [Test] + public void IsRestricted_InvalidChars_Request_2 () + { + // Not allowed: + // 0-32 + // 34 + // 39-41 + // 44 + // 47 + // 91-93 + // 123 + // 125 + // >= 127 + int [] singles = new int [] { 34, 44, 47, 123, 125 }; + foreach (int single in singles) { + try { + WebHeaderCollection.IsRestricted (new string ((char) single, 1), false); + Assert.Fail (String.Format ("{0}: {1}", single, (char) single)); + } catch (ArgumentException) { + } + } + for (int i = 0; i <= 32; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1), false); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + for (int i = 39; i <= 41; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1), false); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + for (int i = 91; i <= 93; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1), false); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + for (int i = 127; i <= 255; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1), false); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + } + + [Test] + public void IsRestricted_InvalidChars_Response_2 () + { + // Not allowed: + // 0-32 + // 34 + // 39-41 + // 44 + // 47 + // 91-93 + // 123 + // 125 + // >= 127 + int [] singles = new int [] { 34, 44, 47, 123, 125 }; + foreach (int single in singles) { + try { + WebHeaderCollection.IsRestricted (new string ((char) single, 1), true); + Assert.Fail (String.Format ("{0}: {1}", single, (char) single)); + } catch (ArgumentException) { + } + } + for (int i = 0; i <= 32; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1), true); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + for (int i = 39; i <= 41; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1), true); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + for (int i = 91; i <= 93; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1), true); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + for (int i = 127; i <= 255; i++) { + try { + WebHeaderCollection.IsRestricted (new string ((char) i, 1), true); + Assert.Fail (String.Format ("{0}: {1}", i, (char) i)); + } catch (ArgumentException) { + } + } + } + static string [] request_headers = new string [] { "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language", "Accept-Ranges", "Authorization", "Cache-Control", "Connection", "Cookie", "Content-Length", "Content-Type", "Date", |