55namespace Keboola \Test \Backend \Workspaces ;
66
77use Exception ;
8- use Keboola \StorageApi \ BranchAwareClient ;
8+ use Keboola \Csv \ CsvFile ;
99use Keboola \StorageApi \Workspaces ;
1010use Keboola \TableBackendUtils \Escaping \Snowflake \SnowflakeQuote ;
1111use Keboola \Test \Backend \WorkspaceConnectionTrait ;
@@ -102,7 +102,7 @@ public function testConnectByCredentials(): void
102102 $ workspaceCredentialsRefreshed = $ workspaces ->getCredentials ($ workspace ['id ' ], $ credentialsId );
103103 $ this ->assertEventWithRetries ($ this ->_client , $ assertCallback , $ query );
104104 $ this ->assertEquals ($ workspaceCredentials ['connection ' ]['privateKey ' ], $ workspaceCredentialsRefreshed ['connection ' ]['privateKey ' ]);
105- $ workspaceBackendRefreshed = WOrkspaceBackendFactory ::createWorkspaceBackend ($ workspaceCredentialsRefreshed , true );
105+ $ workspaceBackendRefreshed = WorkspaceBackendFactory ::createWorkspaceBackend ($ workspaceCredentialsRefreshed , true );
106106
107107 $ dbResultRefreshed = $ workspaceBackendRefreshed ->fetchAll ('test_Languages ' );
108108
@@ -126,4 +126,67 @@ public function testConnectByCredentials(): void
126126 $ this ->assertTrue (str_contains ($ e ->getMessage (), 'JWT token is invalid. ' ));
127127 }
128128 }
129+
130+ public function testCredentialsWithROAccess (): void
131+ {
132+ $ this ->expectNotToPerformAssertions ();
133+ $ workspace = $ this ->initTestWorkspace (
134+ options: ['backend ' => 'snowflake ' , 'readOnlyStorageAccess ' => true ],
135+ forceRecreate: true ,
136+ );
137+ $ workspaces = new Workspaces ($ this ->workspaceSapiClient );
138+ $ retrievedCredentials = $ workspaces ->createCredentials ($ workspace ['id ' ]);
139+
140+ // Create table in storage
141+ $ bucketId = $ this ->getTestBucketId (self ::STAGE_IN );
142+ $ bucketDetail = $ this ->_client ->getBucket ($ bucketId );
143+ $ this ->_client ->createTableAsync (
144+ $ bucketId ,
145+ 'test-table ' ,
146+ new CsvFile (__DIR__ . '/../../_data/languages.csv ' ),
147+ );
148+
149+ $ backend = WorkspaceBackendFactory::createWorkspaceBackend ($ retrievedCredentials , true );
150+ $ backend ->executeQuery (
151+ sprintf (
152+ 'SELECT * FROM %s.%s ' ,
153+ SnowflakeQuote::quoteSingleIdentifier ($ bucketDetail ['path ' ]),
154+ SnowflakeQuote::quoteSingleIdentifier ('test-table ' ),
155+ ),
156+ );
157+ }
158+
159+ public function testCredentialsWithoutROAccess (): void
160+ {
161+ $ workspace = $ this ->initTestWorkspace (
162+ options: ['backend ' => 'snowflake ' , 'readOnlyStorageAccess ' => false ],
163+ forceRecreate: true ,
164+ );
165+ $ workspaces = new Workspaces ($ this ->workspaceSapiClient );
166+ $ retrievedCredentials = $ workspaces ->createCredentials ($ workspace ['id ' ]);
167+
168+ // Create table in storage
169+ $ bucketId = $ this ->getTestBucketId (self ::STAGE_IN );
170+ $ bucketDetail = $ this ->_client ->getBucket ($ bucketId );
171+ $ this ->_client ->createTableAsync (
172+ $ bucketId ,
173+ 'test-table ' ,
174+ new CsvFile (__DIR__ . '/../../_data/languages.csv ' ),
175+ );
176+
177+ $ backend = WorkspaceBackendFactory::createWorkspaceBackend ($ retrievedCredentials , true );
178+
179+ try {
180+ $ backend ->executeQuery (
181+ sprintf (
182+ 'SELECT * FROM %s.%s ' ,
183+ SnowflakeQuote::quoteSingleIdentifier ($ bucketDetail ['path ' ]),
184+ SnowflakeQuote::quoteSingleIdentifier ('test-table ' ),
185+ ),
186+ );
187+ $ this ->fail ('Expected exception to be thrown. ' );
188+ } catch (Exception $ e ) {
189+ $ this ->assertStringContainsString ('does not exist or not authorized ' , $ e ->getMessage ());
190+ }
191+ }
129192}
0 commit comments