Skip to content

Commit

Permalink
assign NP to project on beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkasemmler committed Nov 27, 2024
1 parent ead84ef commit b4f903a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/Backend/NetworkPolicies/NetworkPoliciesTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ private function getDBPrefix(): string
return $dbPrefix;
}

protected function assignNetworkPolicyToProjectUser(int $projectId, string $networkPolicyName): void
{
$db = $this->ensureSnowflakeConnection();
$this->useRoleAccountAdmin();

$projectUserName = $this->getDBPrefix() . $projectId;
$query = \sprintf('ALTER USER %s SET NETWORK_POLICY = %s ', $projectUserName, $networkPolicyName);
$db->executeQuery($query);
}

private function useRoleAccountAdmin(): void
{
$db = $this->ensureSnowflakeConnection();
Expand Down
11 changes: 11 additions & 0 deletions tests/Backend/NetworkPolicies/SnowflakeNetworkPoliciesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,16 @@ public function testAccessWithoutNetworkPolicy(): void
public function testAccessWithSystemNetworkPolicy(): void
{
$systemNetworkPolicyName = $this->defaultNetworkPolicyName();
$verifiedToken = $this->_client->verifyToken();

if (!$this->networkPolicyExists($systemNetworkPolicyName)) {
$this->createNetworkPolicy($systemNetworkPolicyName);
}

// the project might not have the NP enabled -> so do it manually.
// Keep in mind that it might not have the feature set, but it is ok
$this->assignNetworkPolicyToProjectUser($verifiedToken['owner']['id'], $systemNetworkPolicyName);

$this->assertNetworkPolicyExists($systemNetworkPolicyName);

$testNetworkRuleName = $this->defaultTestsNetworkRuleName();
Expand Down Expand Up @@ -85,14 +90,20 @@ public function testAccessWithSystemNetworkPolicy(): void
$this->dropNetworkRule($testNetworkRuleName);
}

// this test won't be working locally because IP of local connection and IP of test runner are the same
public function testAccessWithPrivateIpInNetworkPolicy(): void
{
$systemNetworkPolicyName = $this->defaultNetworkPolicyName();
$verifiedToken = $this->_client->verifyToken();

if (!$this->networkPolicyExists($systemNetworkPolicyName)) {
$this->createNetworkPolicy($systemNetworkPolicyName);
}

// the project might not have the NP enabled -> so do it manually.
// Keep in mind that it might not have the feature set, but it is ok
$this->assignNetworkPolicyToProjectUser($verifiedToken['owner']['id'], $systemNetworkPolicyName);

$this->assertNetworkPolicyExists($systemNetworkPolicyName);

$testNetworkRuleName = $this->defaultTestsNetworkRuleName();
Expand Down

0 comments on commit b4f903a

Please sign in to comment.