mod_admin_telnet: Identify native bidi sessions
[prosody.git] / spec / util_http_spec.lua
blobd38645f7100cdad87d0d81fd452d977af6168207
2 local http = require "util.http";
4 describe("util.http", function()
5 describe("#urlencode()", function()
6 it("should not change normal characters", function()
7 assert.are.equal(http.urlencode("helloworld123"), "helloworld123");
8 end);
10 it("should escape spaces", function()
11 assert.are.equal(http.urlencode("hello world"), "hello%20world");
12 end);
14 it("should escape important URL characters", function()
15 assert.are.equal(http.urlencode("This & that = something"), "This%20%26%20that%20%3d%20something");
16 end);
17 end);
19 describe("#urldecode()", function()
20 it("should not change normal characters", function()
21 assert.are.equal("helloworld123", http.urldecode("helloworld123"), "Normal characters not escaped");
22 end);
24 it("should decode spaces", function()
25 assert.are.equal("hello world", http.urldecode("hello%20world"), "Spaces escaped");
26 end);
28 it("should decode important URL characters", function()
29 assert.are.equal("This & that = something", http.urldecode("This%20%26%20that%20%3d%20something"), "Important URL chars escaped");
30 end);
32 it("should decode both lower and uppercase", function ()
33 assert.are.equal("This & that = {something}.", http.urldecode("This%20%26%20that%20%3D%20%7Bsomething%7D%2E"), "Important URL chars escaped");
34 end);
36 end);
38 describe("#formencode()", function()
39 it("should encode basic data", function()
40 assert.are.equal(http.formencode({ { name = "one", value = "1"}, { name = "two", value = "2" } }), "one=1&two=2", "Form encoded");
41 end);
43 it("should encode special characters with escaping", function()
44 assert.are.equal(http.formencode({ { name = "one two", value = "1"}, { name = "two one&", value = "2" } }), "one+two=1&two+one%26=2", "Form encoded");
45 end);
46 end);
48 describe("#formdecode()", function()
49 it("should decode basic data", function()
50 local t = http.formdecode("one=1&two=2");
51 assert.are.same(t, {
52 { name = "one", value = "1" };
53 { name = "two", value = "2" };
54 one = "1";
55 two = "2";
56 });
57 end);
59 it("should decode special characters", function()
60 local t = http.formdecode("one+two=1&two+one%26=2");
61 assert.are.same(t, {
62 { name = "one two", value = "1" };
63 { name = "two one&", value = "2" };
64 ["one two"] = "1";
65 ["two one&"] = "2";
66 });
67 end);
68 end);
70 describe("normalize_path", function ()
71 it("root path is always '/'", function ()
72 assert.equal("/", http.normalize_path("/"));
73 assert.equal("/", http.normalize_path(""));
74 assert.equal("/", http.normalize_path("/", true));
75 assert.equal("/", http.normalize_path("", true));
76 end);
78 it("works", function ()
79 assert.equal("/foo", http.normalize_path("foo"));
80 assert.equal("/foo", http.normalize_path("/foo"));
81 assert.equal("/foo", http.normalize_path("foo/"));
82 assert.equal("/foo", http.normalize_path("/foo/"));
83 end);
85 it("is_dir works", function ()
86 assert.equal("/foo/", http.normalize_path("foo", true));
87 assert.equal("/foo/", http.normalize_path("/foo", true));
88 assert.equal("/foo/", http.normalize_path("foo/", true));
89 assert.equal("/foo/", http.normalize_path("/foo/", true));
90 end);
91 end);
92 end);