1
1
<?php
2
2
3
3
use Dapphp \Radius \Radius ;
4
+ use Dapphp \Radius \EAPPacket ;
5
+ use Dapphp \Radius \MsChapV2Packet ;
6
+ use Dapphp \Radius \VendorId ;
4
7
5
8
class ClientTest extends PHPUnit_Framework_TestCase
6
9
{
10
+ public function testAttributes ()
11
+ {
12
+ $ client = new Radius ();
13
+
14
+ // string value test
15
+ $ test = 'this is a test ' ;
16
+
17
+ $ client ->setAttribute (80 , $ test );
18
+ $ attr = $ client ->getAttributesToSend (80 );
19
+ $ this ->assertEquals ($ test , $ attr );
20
+
21
+ $ client ->removeAttribute (80 );
22
+ $ attr = $ client ->getAttributesToSend (80 );
23
+ $ this ->assertEquals (null , $ attr );
24
+
25
+ // integer value test
26
+ $ nasPort = 32768 ;
27
+
28
+ $ client ->setAttribute (5 , $ nasPort );
29
+ $ attr = $ client ->getAttributesToSend (5 );
30
+ $ this ->assertEquals ($ nasPort , $ attr );
31
+
32
+ $ client ->removeAttribute (5 );
33
+ $ attr = $ client ->getAttributesToSend (5 );
34
+ $ this ->assertEquals (null , $ attr );
35
+ }
36
+
37
+ public function testGetAttributes ()
38
+ {
39
+ $ client = new Radius ();
40
+ $ username = 'LinusX2@arpa.net ' ;
41
+ $ nasIp = '192.168.88.1 ' ;
42
+ $ nasPort = 64000 ;
43
+
44
+ $ expected = '' ; // manually constructed hex string
45
+ $ expected .= chr (1 ); // username
46
+ $ expected .= chr (2 + strlen ($ username )); // length
47
+ $ expected .= $ username ;
48
+
49
+ $ expected .= chr (4 ); // nas ip
50
+ $ expected .= chr (6 );
51
+ $ expected .= pack ('N ' , ip2long ($ nasIp ));
52
+
53
+ $ expected .= chr (5 ); // nas port
54
+ $ expected .= chr (6 );
55
+ $ expected .= pack ('N ' , $ nasPort );
56
+
57
+
58
+ $ client ->setUsername ($ username )
59
+ ->setNasIPAddress ($ nasIp )
60
+ ->setNasPort ($ nasPort );
61
+
62
+ $ actual = implode ('' , $ client ->getAttributesToSend ());
63
+
64
+ $ this ->assertEquals ($ expected , $ actual );
65
+ $ this ->assertEquals ($ username , $ client ->getAttributesToSend (1 ));
66
+ $ this ->assertEquals ($ nasIp , $ client ->getAttributesToSend (4 ));
67
+ $ this ->assertEquals ($ nasPort , $ client ->getAttributesToSend (5 ));
68
+ }
69
+
7
70
public function testEncryptedPassword ()
8
71
{
9
72
$ pass = 'arctangent ' ;
@@ -38,7 +101,7 @@ public function testAuthenticationPacket()
38
101
$ nas = '192.168.1.16 ' ;
39
102
$ nasPort = 3 ;
40
103
41
- $ client = new Radius ();
104
+ $ client = new Radius ();
42
105
43
106
$ client ->setRequestAuthenticator ("\x0f\x40\x3f\x94\x73\x97\x80\x57\xbd\x83\xd5\xcb\x98\xf4\x22\x7a" );
44
107
@@ -114,7 +177,7 @@ public function testMsChapV1Packet()
114
177
115
178
$ client = new Radius ();
116
179
$ client ->setPacketType (Radius::TYPE_ACCESS_REQUEST )
117
- ->setRequestId ($ reqId )
180
+ ->setNextIdentifier ($ reqId )
118
181
->setRequestAuthenticator ($ reqAuth )
119
182
->setSecret ($ secret )
120
183
->setUsername ($ user )
@@ -130,4 +193,63 @@ public function testMsChapV1Packet()
130
193
131
194
$ this ->assertEquals ($ expected , $ packet );
132
195
}
196
+
197
+ public function testEapPacketBasic ()
198
+ {
199
+ $ p = new EAPPacket ();
200
+ $ p ->code = EAPPacket::CODE_REQUEST ;
201
+ $ p ->id = 111 ;
202
+ $ p ->type = EAPPacket::TYPE_IDENTITY ;
203
+ $ p ->data = 'here is some data ' ;
204
+
205
+ $ expected = "016f0016016865726520697320736f6d652064617461 " ;
206
+
207
+ $ this ->assertEquals ($ expected , bin2hex ($ p ->__toString ()));
208
+
209
+ $ parsed = EAPPacket::fromString ($ p ->__toString ());
210
+
211
+ $ this ->assertEquals (EAPPacket::CODE_REQUEST , $ parsed ->code );
212
+ $ this ->assertEquals (111 , $ parsed ->id );
213
+ $ this ->assertEquals (EAPPacket::TYPE_IDENTITY , $ parsed ->type );
214
+ $ this ->assertEquals ($ p ->data , $ parsed ->data );
215
+
216
+ $ p2 = new EAPPacket ();
217
+ $ p2 ->code = EAPPacket::CODE_RESPONSE ;
218
+ $ p2 ->id = 128 ;
219
+ $ p2 ->type = EAPPacket::TYPE_NOTIFICATION ;
220
+ $ p2 ->data = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x99\x98\x97\x96\x95\x94\x93\x92\x91\x90" ;
221
+
222
+ $ p3 = EAPPacket::fromString ($ p2 ->__toString ());
223
+
224
+ $ this ->assertEquals (EAPPacket::CODE_RESPONSE , $ p3 ->code );
225
+ $ this ->assertEquals (128 , $ p3 ->id );
226
+ $ this ->assertEquals (2 , $ p3 ->type );
227
+ $ this ->assertEquals ("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x99\x98\x97\x96\x95\x94\x93\x92\x91\x90" , $ p3 ->data );
228
+ }
229
+
230
+ public function testEapMsChapV2 ()
231
+ {
232
+ $ server = getenv ('RADIUS_SERVER_ADDR ' );
233
+ $ user = getenv ('RADIUS_USER ' );
234
+ $ pass = getenv ('RADIUS_PASS ' );
235
+ $ secret = getenv ('RADIUS_SECRET ' );
236
+
237
+ if (!$ server ) {
238
+ $ this ->markTestSkipped ('RADIUS_SERVER_ADDR environment variable not set ' );
239
+ } elseif (!$ user ) {
240
+ $ this ->markTestSkipped ('RADIUS_USER environment variable not set ' );
241
+ } elseif (!$ pass ) {
242
+ $ this ->markTestSkipped ('RADIUS_PASS environment variable not set ' );
243
+ } elseif (!$ secret ) {
244
+ $ this ->markTestSkipped ('RADIUS_SECRET environment variable not set ' );
245
+ }
246
+
247
+ $ client = new Radius ();
248
+ $ client ->setServer ($ server )
249
+ ->setSecret ($ secret );
250
+
251
+ $ success = $ client ->accessRequestEapMsChapV2 ($ user , $ pass );
252
+
253
+ $ this ->assertTrue ($ success );
254
+ }
133
255
}
0 commit comments