Skip to content

Commit 723c88c

Browse files
Merge pull request #1549 from keboola/roman/dmd-300-change-type-of-legacy-WS-and-unset-pass
DMD-300 - the setPublicKey endpoint called on legacy login type will migrate to SNOWFLAKE_PERSON_KEYPAIR
2 parents c0d9096 + 778e3f9 commit 723c88c

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

tests/Backend/Snowflake/WorkspacesLoginTypesTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Keboola\StorageApi\ClientException;
99
use Keboola\StorageApi\WorkspaceLoginType;
1010
use Keboola\StorageApi\Workspaces;
11+
use Keboola\TableBackendUtils\Connection\Exception\ConnectionException;
1112
use Keboola\Test\Backend\WorkspaceConnectionTrait;
1213
use Keboola\Test\Backend\WorkspaceCredentialsAssertTrait;
1314
use Keboola\Test\Backend\Workspaces\Backend\WorkspaceBackendFactory;
@@ -49,6 +50,64 @@ public static function createWorkspaceProvider(): Generator
4950
}
5051
}
5152

53+
public function legacyLoginTypeProvider(): Generator
54+
{
55+
yield 'Login type "snowflake-legacy-service"' => [
56+
WorkspaceLoginType::SNOWFLAKE_LEGACY_SERVICE_PASSWORD,
57+
];
58+
yield 'Login type "default"' => [
59+
WorkspaceLoginType::DEFAULT,
60+
];
61+
}
62+
63+
/**
64+
* @dataProvider legacyLoginTypeProvider
65+
*/
66+
public function testCreateLegacyWsAndMigrateToPersonKeypairTypeBySetPublicKeyEndpoint(WorkspaceLoginType $loginType): void
67+
{
68+
$workspaces = new Workspaces($this->workspaceSapiClient);
69+
$options['loginType'] = $loginType;
70+
$workspace = $this->initTestWorkspace('snowflake', $options, true);
71+
72+
$connection = $workspace['connection'];
73+
$this->assertSame('snowflake', $connection['backend']);
74+
$this->assertSame('snowflake-legacy-service', $connection['loginType']); // it's always snowflake-legacy-service
75+
76+
$key = (new PemKeyCertificateGenerator())->createPemKeyCertificate(null);
77+
$workspaces->setPublicKey($workspace['id'], new Workspaces\SetPublicKeyRequest(publicKey: $key->getPublicKey()));
78+
$updatedWs = $workspaces->getWorkspace($workspace['id']);
79+
80+
$connectionWs = $updatedWs['connection'];
81+
$this->assertSame('snowflake', $connectionWs['backend']);
82+
assert(array_key_exists('loginType', $connectionWs));
83+
$this->assertSame(WorkspaceLoginType::SNOWFLAKE_PERSON_KEYPAIR->value, $connectionWs['loginType']);
84+
85+
try {
86+
$backendKey = WorkspaceBackendFactory::createWorkspaceForSnowflakeDbal($workspace);
87+
$backendKey->getDb()->executeQuery('SELECT 1');
88+
$this->fail('Original password should not work');
89+
} catch (ConnectionException $e) {
90+
$this->assertSame('An exception occurred in the driver: Incorrect username or password was specified.', $e->getMessage());
91+
}
92+
93+
// new key pair should work
94+
unset($workspace['connection']['password']);
95+
$workspace['connection']['privateKey'] = $key->getPrivateKey();
96+
$backendKey = WorkspaceBackendFactory::createWorkspaceForSnowflakeDbal($workspace);
97+
$backendKey->getDb()->executeQuery('SELECT 1');
98+
99+
try {
100+
// try reset password
101+
$workspaces->resetWorkspacePassword($workspace['id']);
102+
$this->fail('Password reset should not be supported for keypair login type');
103+
} catch (ClientException $e) {
104+
$this->assertSame($e->getCode(), 400);
105+
$this->assertSame('workspace.resetPasswordNotSupported', $e->getStringCode());
106+
}
107+
108+
$workspaces->deleteWorkspace($workspace['id'], [], true);
109+
}
110+
52111
/**
53112
* @dataProvider createWorkspaceProvider
54113
*/

0 commit comments

Comments
 (0)