[vlc-commits] http: test case for quoted token value extraction
Rémi Denis-Courmont
git at videolan.org
Tue Aug 30 20:54:41 CEST 2016
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Aug 30 21:32:11 2016 +0300| [f8f446edcae6b86af20c8f54c5a53bf00ebe181e] | committer: Rémi Denis-Courmont
http: test case for quoted token value extraction
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f8f446edcae6b86af20c8f54c5a53bf00ebe181e
---
modules/access/http/message_test.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/modules/access/http/message_test.c b/modules/access/http/message_test.c
index 74ceb8f..003f14a 100644
--- a/modules/access/http/message_test.c
+++ b/modules/access/http/message_test.c
@@ -159,6 +159,27 @@ static time_t parse_date(const char *str)
return t1;
}
+static const char *check_realm(const char *line, const char *realm)
+{
+ struct vlc_http_msg *m;
+ char *value;
+
+ m = vlc_http_resp_create(401);
+ assert(m != NULL);
+ assert(vlc_http_msg_add_header(m, "WWW-Authenticate", "%s", line) == 0);
+ value = vlc_http_msg_get_basic_realm(m);
+ if (realm == NULL)
+ assert(value == NULL);
+ else
+ {
+ assert(value != NULL);
+ assert(!strcmp(value, realm));
+ free(value);
+ }
+ vlc_http_msg_destroy(m);
+ return realm;
+}
+
int main(void)
{
struct vlc_http_msg *m;
@@ -202,6 +223,15 @@ int main(void)
assert(parse_date("Sun, 06 Bug 1994 08:49:37 GMT") == -1);
assert(parse_date("bogus") == -1);
+ assert(check_realm("Basic realm=\"kingdom\"", "kingdom"));
+ assert(check_realm("BaSiC REALM= \"kingdom\"", "kingdom"));
+ assert(check_realm("basic Realm\t=\"kingdom\"", "kingdom"));
+ assert(check_realm("Basic charset=\"utf-8\", realm=\"kingdom\"",
+ "kingdom"));
+ assert(check_realm("Basic realm=\"Realm is \\\"Hello world!\\\"\"",
+ "Realm is \"Hello world!\""));
+ assert(check_realm("Basic", NULL) == NULL);
+
m = vlc_http_req_create("PRI", "https", "*", NULL);
assert(m != NULL);
More information about the vlc-commits
mailing list