3131use Pterodactyl \Models \Server ;
3232use Tests \Assertions \ControllerAssertionsTrait ;
3333use Pterodactyl \Http \Controllers \Base \IndexController ;
34- use Pterodactyl \Services \Servers \ ServerAccessHelperService ;
34+ use Pterodactyl \Services \DaemonKeys \ DaemonKeyProviderService ;
3535use Pterodactyl \Contracts \Repository \ServerRepositoryInterface ;
3636use Pterodactyl \Contracts \Repository \Daemon \ServerRepositoryInterface as DaemonServerRepositoryInterface ;
3737
3838class IndexControllerTest extends TestCase
3939{
4040 use ControllerAssertionsTrait;
4141
42- /**
43- * @var \Pterodactyl\Services\Servers\ServerAccessHelperService
44- */
45- protected $ access ;
46-
4742 /**
4843 * @var \Pterodactyl\Http\Controllers\Base\IndexController
4944 */
5045 protected $ controller ;
5146
5247 /**
53- * @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface
48+ * @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface|\Mockery\Mock
5449 */
5550 protected $ daemonRepository ;
5651
5752 /**
58- * @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
53+ * @var \Pterodactyl\Services\DaemonKeys\DaemonKeyProviderService|\Mockery\Mock
54+ */
55+ protected $ keyProviderService ;
56+
57+ /**
58+ * @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface|\Mockery\Mock
5959 */
6060 protected $ repository ;
6161
6262 /**
63- * @var \Illuminate\Http\Request
63+ * @var \Illuminate\Http\Request|\Mockery\Mock
6464 */
6565 protected $ request ;
6666
@@ -71,12 +71,12 @@ public function setUp()
7171 {
7272 parent ::setUp ();
7373
74- $ this ->access = m::mock (ServerAccessHelperService::class);
7574 $ this ->daemonRepository = m::mock (DaemonServerRepositoryInterface::class);
75+ $ this ->keyProviderService = m::mock (DaemonKeyProviderService::class);
7676 $ this ->repository = m::mock (ServerRepositoryInterface::class);
7777 $ this ->request = m::mock (Request::class);
7878
79- $ this ->controller = new IndexController ($ this ->daemonRepository , $ this ->access , $ this ->repository );
79+ $ this ->controller = new IndexController ($ this ->keyProviderService , $ this ->daemonRepository , $ this ->repository );
8080 }
8181
8282 /**
@@ -109,16 +109,17 @@ public function testStatusController()
109109 $ server = factory (Server::class)->make (['suspended ' => 0 , 'installed ' => 1 ]);
110110
111111 $ this ->request ->shouldReceive ('user ' )->withNoArgs ()->once ()->andReturn ($ user );
112- $ this ->access ->shouldReceive ('handle ' )->with ($ server ->uuid , $ user )->once ()->andReturn ($ server );
112+ $ this ->repository ->shouldReceive ('findFirstWhere ' )->with ([['uuidShort ' , '= ' , $ server ->uuidShort ]])->once ()->andReturn ($ server );
113+ $ this ->keyProviderService ->shouldReceive ('handle ' )->with ($ server ->id , $ user ->id )->once ()->andReturn ('test123 ' );
113114
114115 $ this ->daemonRepository ->shouldReceive ('setNode ' )->with ($ server ->node_id )->once ()->andReturnSelf ()
115116 ->shouldReceive ('setAccessServer ' )->with ($ server ->uuid )->once ()->andReturnSelf ()
116- ->shouldReceive ('setAccessToken ' )->with ($ server -> daemonSecret )->once ()->andReturnSelf ()
117+ ->shouldReceive ('setAccessToken ' )->with (' test123 ' )->once ()->andReturnSelf ()
117118 ->shouldReceive ('details ' )->withNoArgs ()->once ()->andReturnSelf ();
118119
119120 $ this ->daemonRepository ->shouldReceive ('getBody ' )->withNoArgs ()->once ()->andReturn ('["test"] ' );
120121
121- $ response = $ this ->controller ->status ($ this ->request , $ server ->uuid );
122+ $ response = $ this ->controller ->status ($ this ->request , $ server ->uuidShort );
122123 $ this ->assertIsJsonResponse ($ response );
123124 $ this ->assertResponseJsonEquals (['test ' ], $ response );
124125 }
@@ -132,9 +133,10 @@ public function testStatusControllerWhenServerNotInstalled()
132133 $ server = factory (Server::class)->make (['suspended ' => 0 , 'installed ' => 0 ]);
133134
134135 $ this ->request ->shouldReceive ('user ' )->withNoArgs ()->once ()->andReturn ($ user );
135- $ this ->access ->shouldReceive ('handle ' )->with ($ server ->uuid , $ user )->once ()->andReturn ($ server );
136+ $ this ->repository ->shouldReceive ('findFirstWhere ' )->with ([['uuidShort ' , '= ' , $ server ->uuidShort ]])->once ()->andReturn ($ server );
137+ $ this ->keyProviderService ->shouldReceive ('handle ' )->with ($ server ->id , $ user ->id )->once ()->andReturn ('test123 ' );
136138
137- $ response = $ this ->controller ->status ($ this ->request , $ server ->uuid );
139+ $ response = $ this ->controller ->status ($ this ->request , $ server ->uuidShort );
138140 $ this ->assertIsJsonResponse ($ response );
139141 $ this ->assertResponseCodeEquals (200 , $ response );
140142 $ this ->assertResponseJsonEquals (['status ' => 20 ], $ response );
@@ -149,9 +151,10 @@ public function testStatusControllerWhenServerIsSuspended()
149151 $ server = factory (Server::class)->make (['suspended ' => 1 , 'installed ' => 1 ]);
150152
151153 $ this ->request ->shouldReceive ('user ' )->withNoArgs ()->once ()->andReturn ($ user );
152- $ this ->access ->shouldReceive ('handle ' )->with ($ server ->uuid , $ user )->once ()->andReturn ($ server );
154+ $ this ->repository ->shouldReceive ('findFirstWhere ' )->with ([['uuidShort ' , '= ' , $ server ->uuidShort ]])->once ()->andReturn ($ server );
155+ $ this ->keyProviderService ->shouldReceive ('handle ' )->with ($ server ->id , $ user ->id )->once ()->andReturn ('test123 ' );
153156
154- $ response = $ this ->controller ->status ($ this ->request , $ server ->uuid );
157+ $ response = $ this ->controller ->status ($ this ->request , $ server ->uuidShort );
155158 $ this ->assertIsJsonResponse ($ response );
156159 $ this ->assertResponseCodeEquals (200 , $ response );
157160 $ this ->assertResponseJsonEquals (['status ' => 30 ], $ response );
0 commit comments