Subham-KRLX commented on code in PR #4614:
URL: https://github.com/apache/iggy/pull/4614#discussion_r4339206819
##########
foreign/cpp/tests/e2e/client.cpp:
##########
@@ -3025,3 +3025,142 @@ TEST_F(LowLevelE2E_Client,
SendBinaryRequestUnknownCommandCodeThrows) {
EXPECT_FALSE(error_info.has_operation_id);
EXPECT_EQ(error_info.operation_id, 0u);
}
+
+TEST_F(E2E_Client, CreatePersonalAccessTokenBeforeLoginThrows) {
+ RecordProperty("description", "Rejects personal access token creation
without an active authenticated session.");
+ auto root_client = GetLoggedInHighLevelClient();
+ const std::string username = GetRandomName(30);
+ ASSERT_NO_THROW({ CreateUser(root_client, username, "secret123",
iggy::UserStatus::Active); });
+ auto client = GetLoggedOutHighLevelClient();
+ const std::string token_name = GetRandomName(30);
+
+ ASSERT_THROW(client.CreatePersonalAccessToken(token_name,
iggy::Expiry::ServerDefault()), iggy::IggyException);
+ ASSERT_NO_THROW(client.Connect());
+ ASSERT_THROW(client.CreatePersonalAccessToken(token_name,
iggy::Expiry::ServerDefault()), iggy::IggyException);
+ ASSERT_NO_THROW(client.Login(username, "secret123"));
+ std::string token;
+ ASSERT_NO_THROW({ token = client.CreatePersonalAccessToken(token_name,
iggy::Expiry::ServerDefault()); });
+ EXPECT_FALSE(token.empty());
+}
+
+TEST_F(E2E_Client, CreatePersonalAccessTokenReturnsTokenString) {
+ RecordProperty("description", "Creates tokens with ASCII and multibyte
UTF-8 names and returns their raw strings.");
+ auto root_client = GetLoggedInHighLevelClient();
+ const std::string username = GetRandomName(30);
+ ASSERT_NO_THROW({ CreateUser(root_client, username, "secret123",
iggy::UserStatus::Active); });
+ auto client =
GetLoggedInHighLevelClient(username, "secret123");
+ const std::vector<std::string> token_names = {
+ "ascii-token",
+ "caf\xc3\xa9",
+ "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e",
+ "token-\xf0\x9f\x8d\xb7",
+ };
+
+ for (const auto &token_name : token_names) {
+ SCOPED_TRACE(token_name);
+ std::string token;
+ ASSERT_NO_THROW({ token = client.CreatePersonalAccessToken(token_name,
iggy::Expiry::ServerDefault()); });
Review Comment:
Added the bounded expiry test with sleep and the TODO comment in the latest
commit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]