Software /
code /
prosody
Annotate
spec/util_http_spec.lua @ 11226:b3ae48362f78 0.11
mod_s2s: Prevent whitespace keepalives the stream has been opened
This will result in the stream timing out instead, which is probably
correct if the stream has not been opened yet.
This was already done for c2s in e69df8093387
Thanks Ge0rG
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 10 Dec 2020 11:53:10 +0100 |
parent | 9505:5203b6fd34d4 |
child | 9785:ff88b03c343f |
rev | line source |
---|---|
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 local http = require "util.http"; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 describe("util.http", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 describe("#urlencode()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 it("should not change normal characters", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 assert.are.equal(http.urlencode("helloworld123"), "helloworld123"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 it("should escape spaces", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 assert.are.equal(http.urlencode("hello world"), "hello%20world"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 it("should escape important URL characters", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 assert.are.equal(http.urlencode("This & that = something"), "This%20%26%20that%20%3d%20something"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 describe("#urldecode()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 it("should not change normal characters", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 assert.are.equal("helloworld123", http.urldecode("helloworld123"), "Normal characters not escaped"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 it("should decode spaces", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 assert.are.equal("hello world", http.urldecode("hello%20world"), "Spaces escaped"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 it("should decode important URL characters", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 assert.are.equal("This & that = something", http.urldecode("This%20%26%20that%20%3d%20something"), "Important URL chars escaped"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 describe("#formencode()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 it("should encode basic data", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 assert.are.equal(http.formencode({ { name = "one", value = "1"}, { name = "two", value = "2" } }), "one=1&two=2", "Form encoded"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 it("should encode special characters with escaping", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 assert.are.equal(http.formencode({ { name = "one two", value = "1"}, { name = "two one&", value = "2" } }), "one+two=1&two+one%26=2", "Form encoded"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 describe("#formdecode()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 it("should decode basic data", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 local t = http.formdecode("one=1&two=2"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 assert.are.same(t, { |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 { name = "one", value = "1" }; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 { name = "two", value = "2" }; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 one = "1"; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 two = "2"; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 }); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 it("should decode special characters", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 local t = http.formdecode("one+two=1&two+one%26=2"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 assert.are.same(t, { |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 { name = "one two", value = "1" }; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 { name = "two one&", value = "2" }; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 ["one two"] = "1"; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 ["two one&"] = "2"; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 }); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 end); |
9505
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
64 |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
65 describe("normalize_path", function () |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
66 it("root path is always '/'", function () |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
67 assert.equal("/", http.normalize_path("/")); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
68 assert.equal("/", http.normalize_path("")); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
69 assert.equal("/", http.normalize_path("/", true)); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
70 assert.equal("/", http.normalize_path("", true)); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
71 end); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
72 |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
73 it("works", function () |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
74 assert.equal("/foo", http.normalize_path("foo")); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
75 assert.equal("/foo", http.normalize_path("/foo")); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
76 assert.equal("/foo", http.normalize_path("foo/")); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
77 assert.equal("/foo", http.normalize_path("/foo/")); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
78 end); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
79 |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
80 it("is_dir works", function () |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
81 assert.equal("/foo/", http.normalize_path("foo", true)); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
82 assert.equal("/foo/", http.normalize_path("/foo", true)); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
83 assert.equal("/foo/", http.normalize_path("foo/", true)); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
84 assert.equal("/foo/", http.normalize_path("/foo/", true)); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
85 end); |
5203b6fd34d4
util.http: Add tests for normalize_path
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
86 end); |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 end); |