1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
public class PlaySpeed : Object {
public double speed = 1.0;
public bool is_positive () { return this.speed >= 0; }
public bool is_normal_rate () { return this.speed == 1.0; }
}
public class HTTPGetHandler : Object {
public int64 get_resource_duration () {
return 0;
}
public bool supports_time_seek () { return true; }
}
public class ClientHacks : Object {
public static ClientHacks? create (Soup.ServerMessage message) throws Error {
throw new NumberParserError.INVALID ("");
}
public bool force_seek () { return false; }
}
public class Soup.MessageHeaders {
private HashTable<string, string> headers;
public MessageHeaders(HashTable<string, string> headers) {
this.headers = headers;
}
public string? get_one (string header) {
return this.headers.lookup (header);
}
}
public class Soup.ServerMessage {
public HashTable<string, string> request_headers = new HashTable<string, string> (str_hash, str_equal);
public MessageHeaders? get_request_headers () {
return new MessageHeaders(request_headers);
}
}
public enum Soup.Status {
BAD_REQUEST = 400,
REQUESTED_RANGE_NOT_SATISFIABLE = 416
}
void test_time_seek_malformed_header () {
// Mock data
var message = new Soup.ServerMessage ();
var handler = new HTTPGetHandler ();
// Test without the header
try {
new Rygel.HTTPTimeSeekRequest (message, handler, null);
assert_not_reached ();
} catch (Error e) {
// Pass - we only expect a HTTPSeekRequestError
assert (e is Rygel.HTTPSeekRequestError.INVALID_RANGE);
}
// Test empty header
message.request_headers.replace (Rygel.HTTPTimeSeekRequest.TIMESEEKRANGE_HEADER, "");
try {
new Rygel.HTTPTimeSeekRequest (message, handler, null);
assert_not_reached ();
} catch (Error e) {
// Pass - we only expect a HTTPSeekRequestError
assert (e is Rygel.HTTPSeekRequestError.INVALID_RANGE);
}
// Test empty header
message.request_headers.replace (Rygel.HTTPTimeSeekRequest.TIMESEEKRANGE_HEADER, "npt=kjalsjd lsdjldskj lkfdsj ");
try {
new Rygel.HTTPTimeSeekRequest (message, handler, null);
assert_not_reached ();
} catch (Error e) {
// Pass - we only expect a HTTPSeekRequestError
assert (e is Rygel.HTTPSeekRequestError.INVALID_RANGE);
}
// Must not have white-spaces before npt=
message.request_headers.replace (Rygel.HTTPTimeSeekRequest.TIMESEEKRANGE_HEADER,
" npt=0.000-");
try {
new Rygel.HTTPTimeSeekRequest (message, handler, null);
assert_not_reached ();
} catch (Error e) {
// Pass - we only expect a HTTPSeekRequestError
assert (e is Rygel.HTTPSeekRequestError.INVALID_RANGE);
}
// Must not have white-spaces in the time
message.request_headers.replace (Rygel.HTTPTimeSeekRequest.TIMESEEKRANGE_HEADER,
"npt = 00 : 05 : 35.3-00");
try {
new Rygel.HTTPTimeSeekRequest (message, handler, null);
assert_not_reached ();
} catch (Error e) {
// Pass - we only expect a HTTPSeekRequestError
assert (e is Rygel.HTTPSeekRequestError.INVALID_RANGE);
}
}
int main(string[] args) {
Intl.setlocale (LocaleCategory.ALL, "C");
Test.init (ref args);
Test.add_func ("/server/time-seek/request", test_time_seek_malformed_header);
return Test.run ();
}
|