66
77namespace Magento \Webapi ;
88
9+ use Magento \TestFramework \Authentication \OauthHelper ;
10+ use Magento \TestFramework \Authentication \Rest \OauthClient ;
911use Magento \TestFramework \Helper \Bootstrap ;
1012
1113/**
@@ -33,6 +35,39 @@ protected function setUp(): void
3335 parent ::setUp ();
3436 }
3537
38+ public function testDisabledIntegrationAsBearer ()
39+ {
40+ $ wsdlUrl = $ this ->_getBaseWsdlUrl () . 'testModule5AllSoapAndRestV1,testModule5AllSoapAndRestV2 ' ;
41+ $ accessCredentials = \Magento \TestFramework \Authentication \OauthHelper::getApiAccessCredentials ()['key ' ];
42+ $ connection = curl_init ($ wsdlUrl );
43+ curl_setopt ($ connection , CURLOPT_RETURNTRANSFER , 1 );
44+ curl_setopt ($ connection , CURLOPT_HTTPHEADER , ['header ' => "Authorization: Bearer " . $ accessCredentials ]);
45+ $ responseContent = curl_exec ($ connection );
46+ $ this ->assertEquals (curl_getinfo ($ connection , CURLINFO_HTTP_CODE ), 401 );
47+ $ this ->assertStringContainsString (
48+ "The consumer isn't authorized to access %resources. " ,
49+ htmlspecialchars_decode ($ responseContent , ENT_QUOTES )
50+ );
51+ }
52+
53+ public function testAuthenticationWithOAuth ()
54+ {
55+ $ wsdlUrl = $ this ->_getBaseWsdlUrl () . 'testModule5AllSoapAndRestV2 ' ;
56+ $ this ->_soapUrl = "{$ this ->_baseUrl }/soap/ {$ this ->_storeCode }?services=testModule5AllSoapAndRestV2 " ;
57+ $ this ->isSingleService = true ;
58+
59+ $ connection = curl_init ($ wsdlUrl );
60+ curl_setopt ($ connection , CURLOPT_RETURNTRANSFER , 1 );
61+ curl_setopt ($ connection , CURLOPT_HTTPHEADER , ['header ' => $ this ->getAuthHeader ($ wsdlUrl )]);
62+ $ responseContent = curl_exec ($ connection );
63+ $ this ->assertEquals (curl_getinfo ($ connection , CURLINFO_HTTP_CODE ), 200 );
64+ $ wsdlContent = $ this ->_convertXmlToString ($ responseContent );
65+ $ this ->checkAll ($ wsdlContent );
66+ }
67+
68+ /**
69+ * @magentoConfigFixture default_store oauth/consumer/enable_integration_as_bearer 1
70+ */
3671 public function testMultiServiceWsdl ()
3772 {
3873 $ this ->_soapUrl = "{$ this ->_baseUrl }/soap/ {$ this ->_storeCode }"
@@ -41,27 +76,20 @@ public function testMultiServiceWsdl()
4176 $ wsdlContent = $ this ->_convertXmlToString ($ this ->_getWsdlContent ($ wsdlUrl ));
4277 $ this ->isSingleService = false ;
4378
44- $ this ->_checkTypesDeclaration ($ wsdlContent );
45- $ this ->_checkPortTypeDeclaration ($ wsdlContent );
46- $ this ->_checkBindingDeclaration ($ wsdlContent );
47- $ this ->_checkServiceDeclaration ($ wsdlContent );
48- $ this ->_checkMessagesDeclaration ($ wsdlContent );
49- $ this ->_checkFaultsDeclaration ($ wsdlContent );
79+ $ this ->checkAll ($ wsdlContent );
5080 }
5181
82+ /**
83+ * @magentoConfigFixture default_store oauth/consumer/enable_integration_as_bearer 1
84+ */
5285 public function testSingleServiceWsdl ()
5386 {
5487 $ this ->_soapUrl = "{$ this ->_baseUrl }/soap/ {$ this ->_storeCode }?services=testModule5AllSoapAndRestV2 " ;
5588 $ wsdlUrl = $ this ->_getBaseWsdlUrl () . 'testModule5AllSoapAndRestV2 ' ;
5689 $ wsdlContent = $ this ->_convertXmlToString ($ this ->_getWsdlContent ($ wsdlUrl ));
5790 $ this ->isSingleService = true ;
5891
59- $ this ->_checkTypesDeclaration ($ wsdlContent );
60- $ this ->_checkPortTypeDeclaration ($ wsdlContent );
61- $ this ->_checkBindingDeclaration ($ wsdlContent );
62- $ this ->_checkServiceDeclaration ($ wsdlContent );
63- $ this ->_checkMessagesDeclaration ($ wsdlContent );
64- $ this ->_checkFaultsDeclaration ($ wsdlContent );
92+ $ this ->checkAll ($ wsdlContent );
6593 }
6694
6795 public function testNoAuthorizedServices ()
@@ -983,4 +1011,28 @@ protected function _checkFaultsComplexTypeSection($wsdlContent)
9831011 'Details wrapped errors (array of wrapped errors) complex types declaration is invalid. '
9841012 );
9851013 }
1014+
1015+ private function getAuthHeader (string $ url ): string
1016+ {
1017+ $ accessCredentials = OauthHelper::getApiAccessCredentials ();
1018+ /** @var OauthClient $oAuthClient */
1019+ $ oAuthClient = $ accessCredentials ['oauth_client ' ];
1020+ return $ oAuthClient ->buildOauthAuthorizationHeader (
1021+ $ url ,
1022+ $ accessCredentials ['key ' ],
1023+ $ accessCredentials ['secret ' ],
1024+ [],
1025+ 'GET '
1026+ )[0 ];
1027+ }
1028+
1029+ private function checkAll (string $ wsdlContent ): void
1030+ {
1031+ $ this ->_checkTypesDeclaration ($ wsdlContent );
1032+ $ this ->_checkPortTypeDeclaration ($ wsdlContent );
1033+ $ this ->_checkBindingDeclaration ($ wsdlContent );
1034+ $ this ->_checkServiceDeclaration ($ wsdlContent );
1035+ $ this ->_checkMessagesDeclaration ($ wsdlContent );
1036+ $ this ->_checkFaultsDeclaration ($ wsdlContent );
1037+ }
9861038}
0 commit comments