File: pop.lua

package info (click to toggle)
lua-uri 0.1%2B20130926%2Bgit14fa255d-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 408 kB
  • ctags: 332
  • sloc: makefile: 53
file content (129 lines) | stat: -rw-r--r-- 4,432 bytes parent folder | download | duplicates (3)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require "uri-test"
local URI = require "uri"

module("test.pop", lunit.testcase, package.seeall)

function test_pop_parse_1 ()
    local uri = assert(URI:new("Pop://rg@MAILSRV.qualcomm.COM"))
    is("pop://rg@mailsrv.qualcomm.com", tostring(uri))
    is("pop", uri:scheme())
    is("rg", uri:userinfo())
    is("mailsrv.qualcomm.com", uri:host())
    is(110, uri:port())
    is("rg", uri:pop_user())
    is("*", uri:pop_auth())
end

function test_pop_parse_2 ()
    local uri = assert(URI:new("pop://rg;AUTH=+APOP@mail.eudora.com:8110"))
    is("pop://rg;auth=+APOP@mail.eudora.com:8110", tostring(uri))
    is("rg;auth=+APOP", uri:userinfo())
    is("mail.eudora.com", uri:host())
    is(8110, uri:port())
    is("rg", uri:pop_user())
    is("+APOP", uri:pop_auth())
end

function test_pop_parse_3 ()
    local uri = assert(URI:new("pop://baz;AUTH=SCRAM-MD5@foo.bar"))
    is("pop://baz;auth=SCRAM-MD5@foo.bar", tostring(uri))
    is("baz;auth=SCRAM-MD5", uri:userinfo())
    is("foo.bar", uri:host())
    is(110, uri:port())
    is("baz", uri:pop_user())
    is("SCRAM-MD5", uri:pop_auth())
end

function test_pop_normalize ()
    local uri = assert(URI:new("Pop://Baz;Auth=*@Foo.Bar:110"))
    is("pop://Baz@foo.bar", tostring(uri))
    is("Baz", uri:userinfo())
    is("foo.bar", uri:host())
    is(110, uri:port())
    is("Baz", uri:pop_user())
    is("*", uri:pop_auth())
end

function test_pop_set_user ()
    local uri = assert(URI:new("pop://host"))
    is(nil, uri:pop_user("foo ;bar"))
    is("pop://foo%20%3Bbar@host", tostring(uri))
    assert_error("empty user not allowed", function () uri:pop_user("") end)
    is("foo ;bar", uri:pop_user(nil))
    is(nil, uri:pop_user())
    is("pop://host", tostring(uri))
end

function test_pop_set_user_bad ()
    local uri = assert(URI:new("pop://foo@host"))
    assert_error("empty user not allowed", function () uri:pop_user("") end)
    is("foo", uri:pop_user())
    is("pop://foo@host", tostring(uri))
    uri = assert(URI:new("pop://foo;auth=+APOP@host"))
    assert_error("user required when auth specified",
                 function () uri:pop_user(nil) end)
    is("foo", uri:pop_user())
    is("+APOP", uri:pop_auth())
    is("pop://foo;auth=+APOP@host", tostring(uri))
end

function test_pop_set_auth ()
    local uri = assert(URI:new("pop://user@host"))
    is("*", uri:pop_auth("foo ;bar"))
    is("pop://user;auth=foo%20%3Bbar@host", tostring(uri))
    is("foo ;bar", uri:pop_auth("*"))
    is("*", uri:pop_auth())
    is("pop://user@host", tostring(uri))
end

function test_pop_set_auth_bad ()
    local uri = assert(URI:new("pop://host"))
    assert_error("auth not allowed without user",
                 function () uri:pop_auth("+APOP") end)
    uri:pop_user("user")
    assert_error("empty auth not allowed", function () uri:pop_auth("") end)
    assert_error("nil auth not allowed", function () uri:pop_auth(nil) end)
    is("pop://user@host", tostring(uri))
end

function test_pop_bad_syntax ()
    is_bad_uri("path not empty", "pop://foo@host/")
    is_bad_uri("user empty", "pop://@host")
    is_bad_uri("user empty with auth", "pop://;auth=+APOP@host")
    is_bad_uri("auth empty", "pop://user;auth=@host")
end

function test_set_userinfo ()
    local uri = assert(URI:new("pop://host"))
    is(nil, uri:userinfo("foo ;bar"))
    is("pop://foo%20%3Bbar@host", tostring(uri))
    is("foo%20%3Bbar", uri:userinfo("foo;auth=+APOP"))
    is("pop://foo;auth=+APOP@host", tostring(uri))
    is("foo;auth=+APOP", uri:userinfo("foo;AUTH=+APOP"))
    is("pop://foo;auth=+APOP@host", tostring(uri))
    is("foo;auth=+APOP", uri:userinfo("bar;auth=*"))
    is("pop://bar@host", tostring(uri))
    is("bar", uri:userinfo(nil))
    is("pop://host", tostring(uri))
end

function test_set_userinfo_bad ()
    local uri = assert(URI:new("pop://host"))
    assert_error("empty userinfo", function () uri:userinfo("") end)
    assert_error("empty user with auth",
                 function () uri:userinfo(";auth=*") end)
    assert_error("empty auth on its own",
                 function () uri:userinfo(";auth=") end)
    assert_error("empty auth with user",
                 function () uri:userinfo("foo;auth=") end)
end

function test_set_path ()
    local uri = assert(URI:new("pop://host"))
    is("", uri:path(""))
    is("", uri:path(nil))
    is("", uri:path())
    assert_error("non-empty path", function () uri:path("/") end)
end

-- vi:ts=4 sw=4 expandtab