/var/www/hkosl.com/imusiccircle/webadmin/libraies/php-console/php-console/tests/Test/Remote/Auth.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
<?php

namespace PhpConsole\Test\Remote;

class 
Auth extends Test {

    public function 
assertFailedAuthInResponse() {
        
$this->assertFalse($this->response->package->auth->isSuccess);
    }

    public function 
assertSuccessAuthInResponse() {
        
$this->assertTrue($this->response->package->auth->isSuccess);
    }

    public function 
testAuthExistInResponsePackage() {
        
$this->setConnectorAuth();
        
$this->sendRequest();
        
$this->assertFailedAuthInResponse();
    }

    public function 
testNoMessagesInFailedAuth() {
        
$this->setConnectorAuth();
        
$this->sendRequest();
        
$this->assertFailedAuthInResponse();
        
$this->assertRandomMessageInResponse(false);
    }

    public function 
testAuthFailsOnWrongToken() {
        
$this->setConnectorAuth();
        
$this->setRequestAuth(null'oops');
        
$this->sendRequest();
        
$this->assertFailedAuthInResponse();
        
$this->assertRandomMessageInResponse(false);
    }

    public function 
testAuthFailsOnWrongPublicKey() {
        
$this->setConnectorAuth();
        
$this->setRequestAuth('oops');
        
$this->sendRequest();
        
$this->assertFailedAuthInResponse();
        
$this->assertRandomMessageInResponse(false);
    }

    public function 
testAuthFailsOnWrongIp() {
        
$this->setConnectorAuth();
        
$this->setRequestAuth(null, \PhpConsole\Test\SERVER_KEYtrue'1.1.1.1');
        
$this->sendRequest();
        
$this->assertFailedAuthInResponse();
        
$this->assertRandomMessageInResponse(false);
    }

    public function 
testAuthSuccessOnNotPublicKeyByIpWithWrongIp() {
        
$this->setConnectorAuth(\PhpConsole\Test\SERVER_KEYfalse);
        
$this->setRequestAuth(null, \PhpConsole\Test\SERVER_KEYfalse'1.1.1.1');
        
$this->sendRequest();
        
$this->assertSuccessAuthInResponse();
        
$this->assertRandomMessageInResponse();
    }

    public function 
testSuccessAuth() {
        
$this->setConnectorAuth();
        
$this->setRequestAuth();
        
$this->sendRequest();
        
$this->assertSuccessAuthInResponse();
        
$this->assertRandomMessageInResponse();
    }

    public function 
testAuthWithPasswordInCustomServerEncoding() {
        if(!
extension_loaded('mbstring')) {
            
$this->markTestSkipped('There is strange bug using iconv in this test');
            return;
        }
        
$password 'Ёпрст';
        
$encoding 'Windows-1251';
        
$encodedPassword $this->convertEncoding($password$encoding'utf-8');
        
$this->request->addScript('set_connector_encoding', array('encoding' => $encoding));
        
$this->setConnectorAuth($encodedPassword);
        
$this->setRequestAuth(null$password);
        
$this->sendRequest();
        
$this->assertSuccessAuthInResponse();
        
$this->assertRandomMessageInResponse();
    }
}