forked from jpatokal/openflights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
59 lines (50 loc) · 1.59 KB
/
login.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
<?php
include_once(dirname(__FILE__) . '/config.php');
//
// Test cases for php/login.php
//
// Standard log in
class SuccessfulLoginTest extends WebTestCase {
function test() {
global $webroot, $settings;
$result = login($this);
$this->assertEqual($result->status, "1");
$this->assertEqual($result->name, $settings['name']);
}
}
// Legacy login test (where name hash was built using uppercase chars)
class LegacyLoginTest extends WebTestCase {
function test() {
global $webroot, $settings;
$name = "LegacyUser";
$password = "foobar";
$hash = md5($password . $name);
$db = db_connect();
$sql = "INSERT INTO users(name,password) VALUES('$name','$hash')";
$result = mysql_query($sql, $db);
$this->assertTrue(mysql_affected_rows() == 1, "Legacy user added");
$result = login($this, $name, $password);
$this->assertEqual($result->status, "1");
$sql = "DELETE FROM users WHERE name='$name'";
$result = mysql_query($sql, $db);
$this->assertTrue(mysql_affected_rows() == 1, "Legacy user deleted");
}
}
// Wrong password
class WrongPasswordLoginTest extends WebTestCase {
function test() {
global $webroot, $settings;
$result = login($this, $settings["name"], "incorrect");
$this->assertEqual($result->status, "0");
}
}
// Login attempt with expired session
class ExpiredSessionTest extends WebTestCase {
function test() {
global $webroot, $settings;
$result = login($this, $settings["name"], $settings["password"], "DEADBEEF");
$this->assertEqual($result->status, "0");
$this->assertText("Session expired");
}
}
?>