Skip to content

Commit

Permalink
tests: add rpk cloud login test
Browse files Browse the repository at this point in the history
Simple rpk cloud login and logout using credentials
and checking that it writes the token to the
rpk.yaml.
  • Loading branch information
r-vasquez committed Jun 5, 2023
1 parent 95f1cfe commit f23d329
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/rptest/clients/rpk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ def cloud_login_cc(self, id, secret):

cmd = [
self._rpk_binary(), "cloud", "login", "--client-id", id,
"--client-secret", secret
"--client-secret", secret, "--save"
]

self._redpanda.logger.debug(
Expand Down
3 changes: 2 additions & 1 deletion tests/rptest/clients/rpk_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def create_profile(self, name):
return self._run_profile(cmd)

def create_profile_simple(self, name, cfg_location):
return self._execute(['create', name, "--from-simple", cfg_location])
return self._run_profile(
['create', name, "--from-simple", cfg_location])

def use_profile(self, name):
cmd = ["use", name]
Expand Down
66 changes: 66 additions & 0 deletions tests/rptest/tests/rpk_cloud_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2023 Redpanda Data, Inc.
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.md
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0

import os
import tempfile
import yaml

from rptest.services.cluster import cluster

from rptest.utils.rpk_config import read_rpk_cfg, clean_runner_rpk_cfg
from rptest.tests.redpanda_test import RedpandaTest
from rptest.services.redpanda import RedpandaService
from rptest.clients.rpk import RpkTool


def get_ci_env_var(env_var):
out = os.environ.get(env_var, None)
if out is None:
is_ci = os.environ.get("CI", "false")
if is_ci == "true":
raise RuntimeError(
f"Expected {env_var} variable to be set in this environment")

return out


class RpkCloudTest(RedpandaTest):
def __init__(self, ctx):
super(RpkCloudTest, self).__init__(test_context=ctx)
self._ctx = ctx
self._rpk = RpkTool(self.redpanda)
clean_runner_rpk_cfg()

@cluster(num_nodes=1)
def test_cloud_login_logout_cc(self):
"""
Test login to cloud via rpk using client
credentials, make sure we store the token and
then delete it when we logout.
"""
id = get_ci_env_var("RPK_TEST_CLIENT_ID")
secret = get_ci_env_var("RPK_TEST_CLIENT_SECRET")
if id is None or secret is None:
self.logger.warn(
"Skipping test, client credentials env vars not found")
return

output = self._rpk.cloud_login_cc(id, secret)
assert "Successfully logged in" in output

# Check for a token present in file.
rpk_yaml = read_rpk_cfg()
assert rpk_yaml["cloud_auth"][0]["auth_token"] is not None

# Check that the token is not there anymore.
output = self._rpk.cloud_logout()
assert "You are now logged out" in output
rpk_yaml = read_rpk_cfg()

assert "auth_token" not in rpk_yaml["cloud_auth"][0]

0 comments on commit f23d329

Please sign in to comment.