2
2
3
3
class PusherCryptoTest extends PHPUnit \Framework \TestCase
4
4
{
5
- protected function setUp ()
5
+ protected function setUp (): void
6
6
{
7
7
if (function_exists ('sodium_crypto_secretbox ' )) {
8
8
$ this ->crypto = new Pusher \PusherCrypto ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ' );
@@ -24,57 +24,51 @@ public function testValidMasterEncryptionKeys()
24
24
$ this ->assertEquals (Pusher \PusherCrypto::parse_master_key ('' , 'dGhpcyBrZXkgaGFzIG5vbnByaW50YWJsZSBjaGFyIAA= ' ), "this key has nonprintable char \x00" );
25
25
}
26
26
27
- /**
28
- * @expectedException \Pusher\PusherException
29
- * @expectedExceptionMessage both
30
- */
31
27
public function testInvalidMasterEncryptionKeyTwoProvided ()
32
28
{
29
+ $ this ->expectException (\Pusher \PusherException::class);
30
+ $ this ->expectExceptionMessage ('both ' );
31
+
33
32
Pusher \PusherCrypto::parse_master_key ('this is 32 bytes 123456789012345 ' , 'dGhpcyBpcyAzMiBieXRlcyAxMjM0NTY3ODkwMTIzNDU= ' );
34
33
}
35
34
36
- /**
37
- * @expectedException \Pusher\PusherException
38
- * @expectedExceptionMessage 32 bytes
39
- */
40
35
public function testInvalidMasterEncryptionKeyTooShort ()
41
36
{
37
+ $ this ->expectException (\Pusher \PusherException::class);
38
+ $ this ->expectExceptionMessage ('32 bytes ' );
39
+
42
40
Pusher \PusherCrypto::parse_master_key ('this is 31 bytes 12345678901234 ' , '' );
43
41
}
44
42
45
- /**
46
- * @expectedException \Pusher\PusherException
47
- * @expectedExceptionMessage 32 bytes
48
- */
49
43
public function testInvalidMasterEncryptionKeyTooLong ()
50
44
{
45
+ $ this ->expectException (\Pusher \PusherException::class);
46
+ $ this ->expectExceptionMessage ('32 bytes ' );
47
+
51
48
Pusher \PusherCrypto::parse_master_key ('this is 33 bytes 1234567890123456 ' , '' );
52
49
}
53
50
54
- /**
55
- * @expectedException \Pusher\PusherException
56
- * @expectedExceptionMessage 32 bytes
57
- */
58
51
public function testInvalidMasterEncryptionKeyBase64TooShort ()
59
52
{
53
+ $ this ->expectException (\Pusher \PusherException::class);
54
+ $ this ->expectExceptionMessage ('32 bytes ' );
55
+
60
56
Pusher \PusherCrypto::parse_master_key ('' , 'dGhpcyBpcyAzMSBieXRlcyAxMjM0NTY3ODkwMTIzNA== ' );
61
57
}
62
58
63
- /**
64
- * @expectedException \Pusher\PusherException
65
- * @expectedExceptionMessage 32 bytes
66
- */
67
59
public function testInvalidMasterEncryptionKeyBase64TooLong ()
68
60
{
61
+ $ this ->expectException (\Pusher \PusherException::class);
62
+ $ this ->expectExceptionMessage ('32 bytes ' );
63
+
69
64
Pusher \PusherCrypto::parse_master_key ('' , 'dGhpcyBpcyAzMyBieXRlcyAxMjM0NTY3ODkwMTIzNDU2 ' );
70
65
}
71
66
72
- /**
73
- * @expectedException \Pusher\PusherException
74
- * @expectedExceptionMessage valid base64
75
- */
76
67
public function testInvalidMasterEncryptionKeyBase64InvalidBase64 ()
77
68
{
69
+ $ this ->expectException (\Pusher \PusherException::class);
70
+ $ this ->expectExceptionMessage ('valid base64 ' );
71
+
78
72
Pusher \PusherCrypto::parse_master_key ('' , 'dGhpcyBpcyAzMyBi!XRlcyAxMjM0NTY3ODkw#TIzNDU2 ' );
79
73
}
80
74
@@ -92,11 +86,10 @@ public function testGenerateSharedSecret()
92
86
$ this ->assertNotEquals (base64_encode ($ crypto2 ->generate_shared_secret ('private-encrypted-channel-a ' )), $ expected );
93
87
}
94
88
95
- /**
96
- * @expectedException \Pusher\PusherException
97
- */
98
89
public function testGenerateSharedSecretNoChannel ()
99
90
{
91
+ $ this ->expectException (\Pusher \PusherException::class);
92
+
100
93
$ this ->crypto ->generate_shared_secret ('' );
101
94
}
102
95
@@ -123,33 +116,30 @@ public function testEncryptDecryptEventValid()
123
116
$ this ->assertEquals ($ decrypted_payload , $ payload );
124
117
}
125
118
126
- /**
127
- * @expectedException \Pusher\PusherException
128
- */
129
119
public function testEncryptPayloadNoChannel ()
130
120
{
121
+ $ this ->expectException (\Pusher \PusherException::class);
122
+
131
123
$ channel = '' ;
132
124
$ payload = "now that's what I call a payload! " ;
133
125
$ encrypted_payload = $ this ->crypto ->encrypt_payload ($ channel , $ payload );
134
126
$ this ->assertEquals ($ encrypted_payload , false );
135
127
}
136
128
137
- /**
138
- * @expectedException \Pusher\PusherException
139
- */
140
129
public function testEncryptPayloadPublicChannel ()
141
130
{
131
+ $ this ->expectException (\Pusher \PusherException::class);
132
+
142
133
$ channel = 'public-static-void-main ' ;
143
134
$ payload = "now that's what I call a payload! " ;
144
135
$ encrypted_payload = $ this ->crypto ->encrypt_payload ($ channel , $ payload );
145
136
$ this ->assertEquals ($ encrypted_payload , false );
146
137
}
147
138
148
- /**
149
- * @expectedException \Pusher\PusherException
150
- */
151
139
public function testDecryptPayloadWrongKey ()
152
140
{
141
+ $ this ->expectException (\Pusher \PusherException::class);
142
+
153
143
$ channel = 'private-encrypted-bla ' ;
154
144
$ payload = "now that's what I call a payload! " ;
155
145
$ encrypted_payload = $ this ->crypto ->encrypt_payload ($ channel , $ payload );
0 commit comments