summaryrefslogtreecommitdiffstats
path: root/src/tests/modules/rest/rest_module.unlang
blob: c78c3805b5230413371ab8b038a77c5f6c4e3d4d (plain)
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
# Pre-set Tmp-String-2 to check correct operator behaviour
update {
	&control:Tmp-String-2 := "foo"
}

# Test "authorize" rest call.  Uses http to a GET end point
rest

debug_control

if (!(&reply:REST-HTTP-Status-Code == 200)) {
	test_fail
}

if (!(&control:Tmp-String-0 == "authorize")) {
	test_fail
}

if (!(&control:Tmp-String-1 == "GET")) {
	test_fail
}

if (!(&control:Tmp-String-1[*] == "/user/<username>/mac/<client>")) {
	test_fail
}

if (!(&control:User-Name == "Bob")) {
	test_fail
}

# The "op" for setting Tmp-String-2 is ^=
if (!(&control:Tmp-String-2[0] == "Bob") || !(&control:Tmp-String-2[1] == "foo")) {
	test_fail
}

# Reset control attributes
update control {
	&Tmp-String-0[*] !* ANY
	&Tmp-String-1[*] !* ANY
	&User-Name[*] !* ANY
}

# Pre-fill NAS-IP-Address to check operator behaviour
update {
	&control:NAS-IP-Address := "10.0.0.10"
}

# Clear previous status code and body
update reply {
	&REST-HTTP-Status-Code !* ANY
	&REST-HTTP-Body !* ANY
}

# Test "accounting" rest call.  Uses https to a POST end point
rest.accounting

if (!(&reply:REST-HTTP-Status-Code == 200)) {
	test_fail
}

if (!(&control:Tmp-String-0 == "accounting")) {
	test_fail
}

if (!(&control:Tmp-String-1 == "POST")) {
	test_fail
}

if (!(&control:Tmp-String-1[*] == "/user/<username>/mac/<client>")) {
	test_fail
}

if (!(&control:User-Name == "Bob")) {
	test_fail
}

if (!(&control:Tmp-String-2[0] == "Bob") || !(&control:Tmp-String-2[1] == "Bob") || !(&control:Tmp-String-2[2] == "foo")) {
	test_fail
}

# NAS IP Address is passed in body data
if (!(&control:NAS-IP-Address[0] == "10.0.0.10") || !(&control:NAS-IP-Address[1] == "192.168.1.1")) {
	test_fail
}

debug_control

# Clear previous status code and body
update reply {
	&REST-HTTP-Status-Code !* ANY
	&REST-HTTP-Body !* ANY
}

# Test "authenticate" rest call.  Uses http basic authentication
rest.authenticate

if (!(&reply:REST-HTTP-Status-Code == 200)) {
	test_fail
}

if (!(&reply:REST-HTTP-Body == "Section: authenticate, User: Bob, Authenticated: true\n")) {
	test_fail
}

# Clear up reply
update reply {
	&REST-HTTP-Status-Code !* ANY
	&REST-HTTP-Body !* ANY
}

test_pass