File tree 5 files changed +57
-1
lines changed
5 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 13
13
"license" : " Apache-2.0" ,
14
14
"require" : {
15
15
"php" : " >=5.4.0" ,
16
- "psr/log" : " ~1.0"
16
+ "psr/log" : " ~1.0" ,
17
+ "ext-json" : " *"
17
18
},
18
19
"require-dev" : {
19
20
"phpunit/phpunit" : " ~4.0" ,
Original file line number Diff line number Diff line change 19
19
use Docnet \JAPI \Controller ;
20
20
use Docnet \JAPI \Exceptions \Routing as RoutingException ;
21
21
use Docnet \JAPI \Exceptions \Auth as AuthException ;
22
+ use Docnet \JAPI \Exceptions \AccessDenied as AccessDeniedException ;
22
23
use Psr \Log \LoggerAwareInterface ;
23
24
24
25
/**
@@ -68,6 +69,8 @@ public function bootstrap($controller_source)
68
69
$ this ->jsonError ($ obj_ex , 404 );
69
70
} catch (AuthException $ obj_ex ) {
70
71
$ this ->jsonError ($ obj_ex , 401 );
72
+ } catch (AccessDeniedException $ obj_ex ) {
73
+ $ this ->jsonError ($ obj_ex , 403 );
71
74
} catch (\Exception $ obj_ex ) {
72
75
$ this ->jsonError ($ obj_ex , $ obj_ex ->getCode ());
73
76
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright 2018 Venditan Limited
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ namespace Docnet \JAPI \Exceptions ;
18
+
19
+ /**
20
+ * AccessDenied Exception
21
+ *
22
+ * @author Kamba Abudu <[email protected] >
23
+ */
24
+ class AccessDenied extends \Exception
25
+ {
26
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ class AccessDenied extends \Docnet \JAPI \Controller
4
+ {
5
+ public function dispatch (){
6
+ throw new \Docnet \JAPI \Exceptions \AccessDenied ('Error Message ' , 403 );
7
+ }
8
+ }
Original file line number Diff line number Diff line change 3
3
require_once ('Controllers/Example.php ' );
4
4
require_once ('Controllers/Exceptional.php ' );
5
5
require_once ('Controllers/Whoops.php ' );
6
+ require_once ('Controllers/AccessDenied.php ' );
6
7
7
8
class JAPITest extends PHPUnit_Framework_TestCase
8
9
{
@@ -134,4 +135,21 @@ public function testNoLogger()
134
135
$ obj_japi ->bootstrap (new Exceptional ());
135
136
}
136
137
138
+ /**
139
+ * Test an AccessDenied Exception codes are correctly passed to jsonError from the bootstrap() method
140
+ */
141
+ public function testBootstrapAccessDeniedErrorCycle ()
142
+ {
143
+ // Mock JAPI
144
+ $ obj_japi = $ this ->getMockBuilder ('\\Docnet \\JAPI ' )->setMethods (['sendResponse ' , 'jsonError ' ])->getMock ();
145
+ $ obj_japi ->expects ($ this ->never ())->method ('sendResponse ' );
146
+ $ obj_japi ->expects ($ this ->once ())->method ('jsonError ' )->with (
147
+ $ this ->equalTo (new \Docnet \JAPI \Exceptions \AccessDenied ('Error Message ' , 403 )),
148
+ $ this ->equalTo (403 )
149
+ );
150
+
151
+ // Dispatch
152
+ $ obj_japi ->bootstrap (new AccessDenied ());
153
+ }
154
+
137
155
}
You can’t perform that action at this time.
0 commit comments