22
33namespace Tests \Feature \Admin ;
44
5+ use Illuminate \Support \Facades \Http ;
56use Laravel \Passport \Client ;
67use ProcessMaker \Models \DevLink ;
78use Tests \Feature \Shared \RequestHelper ;
@@ -11,23 +12,64 @@ class DevLinkTest extends TestCase
1112{
1213 use RequestHelper;
1314
14- public function testIndex ()
15+ public function testIndexStoreClientCredentials ()
1516 {
1617 $ devLink = DevLink::factory ()->create ();
18+
1719 $ params = [
1820 'devlink_id ' => $ devLink ->id ,
1921 'client_id ' => 123 ,
2022 'client_secret ' => 'abc123 ' ,
2123 ];
2224
2325 $ response = $ this ->webCall ('GET ' , route ('devlink.index ' , $ params ));
24- $ response ->assertRedirect ($ devLink ->getOauthRedirectUrl ());
2526
2627 $ devLink ->refresh ();
28+
29+ $ expectedRedirectParams = [
30+ 'client_id ' => 123 ,
31+ 'redirect_url ' => route ('devlink.index ' ),
32+ 'resource_type ' => 'code ' ,
33+ 'state ' => $ devLink ->state ,
34+ ];
35+ $ expectedRedirectUrl = $ devLink ->url . '/oauth/authorize? ' . http_build_query ($ expectedRedirectParams );
36+ $ response ->assertRedirect ($ expectedRedirectUrl );
37+
2738 $ this ->assertEquals ($ devLink ->client_id , $ params ['client_id ' ]);
2839 $ this ->assertEquals ($ devLink ->client_secret , $ params ['client_secret ' ]);
2940 }
3041
42+ public function testIndexStoreOauthCredentials ()
43+ {
44+ $ devLink = DevLink::factory ()->create ([
45+ 'url ' => 'http://remote-instance.test ' ,
46+ ]);
47+
48+ // Generate state uuid
49+ $ devLink ->getOauthRedirectUrl ();
50+
51+ $ getTokenUrl = $ devLink ->url . '/oauth/token ' ;
52+ Http::fake ([
53+ $ getTokenUrl => Http::response ([
54+ 'access_token ' => '123abc ' ,
55+ 'refresh_token ' => '456def ' ,
56+ 'expires_in ' => 3600 ,
57+ ]),
58+ ]);
59+
60+ $ params = [
61+ 'state ' => $ devLink ->state ,
62+ 'code ' => '12345 ' ,
63+ ];
64+ $ response = $ this ->webCall ('GET ' , route ('devlink.index ' , $ params ));
65+ $ response ->assertStatus (200 );
66+
67+ $ devLink ->refresh ();
68+ $ this ->assertEquals ($ devLink ->access_token , '123abc ' );
69+ $ this ->assertEquals ($ devLink ->refresh_token , '456def ' );
70+ $ this ->assertEquals ($ devLink ->expires_in , 3600 );
71+ }
72+
3173 public function testGetOauthClient ()
3274 {
3375 $ devLink = DevLink::factory ()->create ([
0 commit comments