forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ClickHouse#51261 from evillique/users-valid-until
Add VALID UNTIL clause for users
- Loading branch information
Showing
12 changed files
with
183 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import pytest | ||
from datetime import datetime, timedelta | ||
from time import sleep | ||
|
||
from helpers.cluster import ClickHouseCluster | ||
|
||
cluster = ClickHouseCluster(__file__) | ||
node = cluster.add_instance("node") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def started_cluster(): | ||
try: | ||
cluster.start() | ||
yield cluster | ||
|
||
finally: | ||
cluster.shutdown() | ||
|
||
|
||
def test_basic(started_cluster): | ||
# 1. Without VALID UNTIL | ||
node.query("CREATE USER user_basic") | ||
|
||
assert node.query("SHOW CREATE USER user_basic") == "CREATE USER user_basic\n" | ||
assert node.query("SELECT 1", user="user_basic") == "1\n" | ||
|
||
# 2. With valid VALID UNTIL | ||
node.query("ALTER USER user_basic VALID UNTIL '06/11/2040 08:03:20 Z+3'") | ||
|
||
assert ( | ||
node.query("SHOW CREATE USER user_basic") | ||
== "CREATE USER user_basic VALID UNTIL \\'2040-11-06 05:03:20\\'\n" | ||
) | ||
assert node.query("SELECT 1", user="user_basic") == "1\n" | ||
|
||
# 3. With expired VALID UNTIL | ||
node.query("ALTER USER user_basic VALID UNTIL '06/11/2010 08:03:20 Z+3'") | ||
|
||
assert ( | ||
node.query("SHOW CREATE USER user_basic") | ||
== "CREATE USER user_basic VALID UNTIL \\'2010-11-06 05:03:20\\'\n" | ||
) | ||
|
||
error = "Authentication failed" | ||
assert error in node.query_and_get_error("SELECT 1", user="user_basic") | ||
|
||
# 4. Reset VALID UNTIL | ||
node.query("ALTER USER user_basic VALID UNTIL 'infinity'") | ||
|
||
assert node.query("SHOW CREATE USER user_basic") == "CREATE USER user_basic\n" | ||
assert node.query("SELECT 1", user="user_basic") == "1\n" | ||
node.query("DROP USER user_basic") | ||
|
||
# 5. Make VALID UNTIL expire | ||
until_datetime = datetime.today() + timedelta(0, 10) | ||
until_string = until_datetime.strftime("%Y-%m-%d %H:%M:%S") | ||
|
||
node.query(f"CREATE USER user_basic VALID UNTIL '{until_string}'") | ||
|
||
assert node.query("SELECT 1", user="user_basic") == "1\n" | ||
|
||
sleep(12) | ||
|
||
error = "Authentication failed" | ||
assert error in node.query_and_get_error("SELECT 1", user="user_basic") | ||
|
||
|
||
def test_details(started_cluster): | ||
# 1. Does not do anything | ||
node.query("CREATE USER user_details_infinity VALID UNTIL 'infinity'") | ||
|
||
assert ( | ||
node.query("SHOW CREATE USER user_details_infinity") | ||
== "CREATE USER user_details_infinity\n" | ||
) | ||
|
||
# 2. Time only is not supported | ||
node.query("CREATE USER user_details_time_only VALID UNTIL '22:03:40'") | ||
|
||
assert ( | ||
node.query("SHOW CREATE USER user_details_time_only") | ||
== "CREATE USER user_details_time_only VALID UNTIL \\'2023-01-01 22:03:40\\'\n" | ||
) |