6
6
7
7
namespace Magento \Webapi ;
8
8
9
+ use Magento \TestFramework \Authentication \OauthHelper ;
10
+ use Magento \TestFramework \Authentication \Rest \OauthClient ;
9
11
use Magento \TestFramework \Helper \Bootstrap ;
10
12
11
13
/**
@@ -33,6 +35,39 @@ protected function setUp(): void
33
35
parent ::setUp ();
34
36
}
35
37
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
+ */
36
71
public function testMultiServiceWsdl ()
37
72
{
38
73
$ this ->_soapUrl = "{$ this ->_baseUrl }/soap/ {$ this ->_storeCode }"
@@ -41,27 +76,20 @@ public function testMultiServiceWsdl()
41
76
$ wsdlContent = $ this ->_convertXmlToString ($ this ->_getWsdlContent ($ wsdlUrl ));
42
77
$ this ->isSingleService = false ;
43
78
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 );
50
80
}
51
81
82
+ /**
83
+ * @magentoConfigFixture default_store oauth/consumer/enable_integration_as_bearer 1
84
+ */
52
85
public function testSingleServiceWsdl ()
53
86
{
54
87
$ this ->_soapUrl = "{$ this ->_baseUrl }/soap/ {$ this ->_storeCode }?services=testModule5AllSoapAndRestV2 " ;
55
88
$ wsdlUrl = $ this ->_getBaseWsdlUrl () . 'testModule5AllSoapAndRestV2 ' ;
56
89
$ wsdlContent = $ this ->_convertXmlToString ($ this ->_getWsdlContent ($ wsdlUrl ));
57
90
$ this ->isSingleService = true ;
58
91
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 );
65
93
}
66
94
67
95
public function testNoAuthorizedServices ()
@@ -983,4 +1011,28 @@ protected function _checkFaultsComplexTypeSection($wsdlContent)
983
1011
'Details wrapped errors (array of wrapped errors) complex types declaration is invalid. '
984
1012
);
985
1013
}
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
+ }
986
1038
}
0 commit comments