-
Notifications
You must be signed in to change notification settings - Fork 399
/
settings.php
173 lines (148 loc) · 4.76 KB
/
settings.php
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
include_once dirname(__FILE__) . '/config.php';
// Test cases for php/settings.php
// NB: Assumes there is no existing test user (run cleanup.php first!)
/**
* Create new user
*/
class SuccessfulNewUserTest extends WebTestCase {
public function test() {
global $webroot, $settings;
$hash = md5($settings["password"] . strtolower($settings["name"]));
$settings["type"] = "NEW";
$settings["pw"] = $hash;
$this->post($webroot . "php/settings.php", $settings);
$this->assertText('1;');
}
}
/**
* Duplicate username
*/
class DuplicateUserTest extends WebTestCase {
public function test() {
global $webroot, $settings;
$hash = md5($settings["password"] . strtolower($settings["name"]));
$settings["type"] = "NEW";
$settings["pw"] = $hash;
$this->post($webroot . "php/settings.php", $settings);
$this->assertText('0;');
}
}
/**
* Try to manipulate without a session
*/
class LoadEditResetWithoutSessionTest extends WebTestCase {
public function test() {
global $webroot;
$params = array("type" => "EDIT");
$this->post($webroot . "php/settings.php", $params);
$this->assertText('0;');
$params = array("type" => "RESET");
$this->post($webroot . "php/settings.php", $params);
$this->assertText('0;');
}
}
/**
* Try to change pw, but give the wrong password
*/
class ChangePasswordWithWrongOldPasswordTest extends WebTestCase {
public function test() {
global $webroot, $settings;
login($this);
$params = array(
"type" => "EDIT",
"pw" => "newpw",
"oldpw" => "incorrect"
);
$msg = $this->post($webroot . "php/settings.php", $params);
$this->assertText('0;');
// This should fail
$result = login($this, $settings["name"], "newpw");
$this->assertEqual($result->status, "0");
}
}
/**
* Change password
*/
class ChangePasswordTest extends WebTestCase {
public function test() {
global $webroot, $settings;
login($this);
$oldhash = md5($settings["password"] . strtolower($settings["name"]));
$newhash = md5("newpw" . strtolower($settings["name"]));
$params = array(
"type" => "EDIT",
"oldpw" => $oldhash,
"pw" => $newhash
);
$msg = $this->post($webroot . "php/settings.php", $params);
$this->assertText('2;');
// Log out and validate new password
$msg = $this->post($webroot . "php/logout.php");
$result = login($this, $settings["name"], "newpw");
$this->assertEqual($result->status, "1");
// Change it back
$params = array("type" => "EDIT",
"oldpw" => $newhash,
"pw" => $oldhash);
$msg = $this->post($webroot . "php/settings.php", $params);
$this->assertText('2;');
}
}
/**
* Change all other settings
*/
class ChangeSettingsTest extends WebTestCase {
public function test() {
global $webroot, $settings;
login($this);
$params = array(
"type" => "EDIT",
"email" => "new@email.example",
"privacy" => "N",
"locale" => "fi_FI",
"units" => "M",
"editor" => "D"
);
$msg = $this->post($webroot . "php/settings.php", $params);
$this->assertText('2;');
// Validate changes
$dbh = db_connect();
$sth = $dbh->prepare("SELECT * FROM users WHERE name = ?");
$sth->execute([$settings["name"]]);
$row = $sth->fetch();
$this->assertTrue($row["public"] == $params["privacy"], "Public");
$this->assertTrue($row["email"] == $params["email"], "Email");
$this->assertTrue($row["editor"] == $params["editor"], "Editor");
$this->assertTrue($row["units"] == $params["units"], "Units");
$this->assertTrue($row["locale"] == $params["locale"], "Locale");
}
}
/**
* Restore original settings
*/
class RestoreSettingsTest extends WebTestCase {
public function test() {
global $webroot, $settings;
login($this);
$settings["type"] = "EDIT";
$msg = $this->post($webroot . "php/settings.php", $settings);
$this->assertText('2;');
}
}
/**
* Reset (delete) all flights
*/
class ResetFlightsTest extends WebTestCase {
public function test() {
global $webroot;
login($this);
$params = array("type" => "RESET");
$msg = $this->post($webroot . "php/settings.php", $params);
$this->assertText('10;');
// Validate reset
$map = $this->post($webroot . "php/map.php");
$cols = preg_split('/[;\n]/', $map);
$this->assertTrue($cols[0] == "0", "No flights recorded");
}
}