From fa3db16cc77afbc87df180645806bfb4b2e51fc3 Mon Sep 17 00:00:00 2001 From: AlexandrLitkevich Date: Sat, 1 Feb 2025 20:31:48 +0300 Subject: [PATCH] aeon:added the ability to connect from the config Closes #TNTP-1073 --- cli/cmd/aeon.go | 4 +- test/integration/aeon/test_aeon.py | 230 ++++++++++++++--------------- 2 files changed, 115 insertions(+), 119 deletions(-) diff --git a/cli/cmd/aeon.go b/cli/cmd/aeon.go index 72b52d753..4a81e17de 100644 --- a/cli/cmd/aeon.go +++ b/cli/cmd/aeon.go @@ -36,7 +36,8 @@ func newAeonConnectCmd() *cobra.Command { Short: "Connect to the aeon instance", Long: `Connect to the aeon instance. tt aeon connect localhost:50051 -tt aeon connect unix://`, +tt aeon connect unix:// +tt aeon connect -c path instanceName>`, PreRunE: func(cmd *cobra.Command, args []string) error { err := aeonConnectValidateArgs(cmd, args) util.HandleCmdErr(cmd, err) @@ -48,7 +49,6 @@ tt aeon connect unix://`, internalAeonConnect, args) util.HandleCmdErr(cmd, err) }, - // Args: cobra.ExactArgs(1), } aeonCmd.Flags().StringVar(&connectCtx.Ssl.KeyFile, "sslkeyfile", "", diff --git a/test/integration/aeon/test_aeon.py b/test/integration/aeon/test_aeon.py index e93e28983..98df4712e 100644 --- a/test/integration/aeon/test_aeon.py +++ b/test/integration/aeon/test_aeon.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -from subprocess import run +from subprocess import PIPE, STDOUT, run import pytest @@ -81,119 +81,115 @@ def test_cli_ssl_arguments_success(tt_cmd, aeon_ssl, certificates): assert tt.returncode == 0 -# @pytest.mark.parametrize( -# "args, error", -# [ -# ((), "Error: accepts 1 arg(s), received 0"), -# # ( -# # ("localhost:50051", "@aeon_unix_socket"), -# # "Error: accepts 1 arg(s), received 2", -# # ), -# ( -# ( -# "--transport", -# "mode", -# "localhost:50051", -# ), -# 'Error: invalid argument "mode" for "--transport" flag', -# ), -# ( -# ( -# "--transport=ssl", -# "--sslkeyfile=not-exits.key", -# "--sslcertfile={c_public}", -# "--sslcafile={ca}", -# "localhost:50051", -# ), -# 'not valid path to a private SSL key file="not-exits.key"', -# ), -# ( -# ( -# "--transport=ssl", -# "--sslkeyfile={c_private}", -# "--sslcertfile=not-exits.key", -# "--sslcafile={ca}", -# "localhost:50051", -# ), -# 'not valid path to an SSL certificate file="not-exits.key"', -# ), -# ( -# ( -# "--transport=ssl", -# "--sslkeyfile={c_private}", -# "--sslcertfile={c_public}", -# "--sslcafile=not-exits.key", -# "localhost:50051", -# ), -# 'not valid path to trusted certificate authorities (CA) file="not-exits.key"', -# ), -# ( -# ( -# "--sslcafile=not-exits.key", -# "localhost:50051", -# ), -# 'not valid path to trusted certificate authorities (CA) file="not-exits.key"', -# ), -# ( -# ( -# "--transport=ssl", -# "--sslcertfile={c_public}", -# "--sslcafile={ca}", -# "localhost:50051", -# ), -# "files Key and Cert must be specified both", -# ), -# ( -# ( -# "--transport=ssl", -# "--sslkeyfile={c_private}", -# "--sslcafile={ca}", -# "localhost:50051", -# ), -# "files Key and Cert must be specified both", -# ), -# ( -# ( -# "localhost:50051", -# "--transport=ssl", -# "--sslcertfile={c_public}", -# "--sslcafile={ca}", -# "--sslkeyfile", -# ), -# "flag needs an argument: --sslkeyfile", -# ), -# ( -# ( -# "localhost:50051", -# "--transport=ssl", -# "--sslkeyfile={c_private}", -# "--sslcafile={ca}", -# "--sslcertfile", -# ), -# "flag needs an argument: --sslcertfile", -# ), -# ( -# ( -# "localhost:50051", -# "--transport=ssl", -# "--sslkeyfile={c_private}", -# "--sslcertfile={c_public}", -# "--sslcafile", -# ), -# "flag needs an argument: --sslcafile", -# ), -# ], -# ) -# def test_cli_arguments_fail(tt_cmd, certificates, args, error): -# cmd = [str(tt_cmd), *AeonConnectCommand] -# cmd += (a.format(**certificates) for a in args) - -# print(f"Run: {' '.join(cmd)}") -# result = run( -# cmd, -# stderr=STDOUT, -# stdout=PIPE, -# text=True, -# ) -# assert result.returncode != 0 -# assert error in result.stdout +@pytest.mark.parametrize( + "args, error", + [ + ( + ( + "--transport", + "mode", + "localhost:50051", + ), + 'Error: invalid argument "mode" for "--transport" flag', + ), + ( + ( + "--transport=ssl", + "--sslkeyfile=not-exits.key", + "--sslcertfile={c_public}", + "--sslcafile={ca}", + "localhost:50051", + ), + 'not valid path to a private SSL key file="not-exits.key"', + ), + ( + ( + "--transport=ssl", + "--sslkeyfile={c_private}", + "--sslcertfile=not-exits.key", + "--sslcafile={ca}", + "localhost:50051", + ), + 'not valid path to an SSL certificate file="not-exits.key"', + ), + ( + ( + "--transport=ssl", + "--sslkeyfile={c_private}", + "--sslcertfile={c_public}", + "--sslcafile=not-exits.key", + "localhost:50051", + ), + 'not valid path to trusted certificate authorities (CA) file="not-exits.key"', + ), + ( + ( + "--sslcafile=not-exits.key", + "localhost:50051", + ), + 'not valid path to trusted certificate authorities (CA) file="not-exits.key"', + ), + ( + ( + "--transport=ssl", + "--sslcertfile={c_public}", + "--sslcafile={ca}", + "localhost:50051", + ), + "files Key and Cert must be specified both", + ), + ( + ( + "--transport=ssl", + "--sslkeyfile={c_private}", + "--sslcafile={ca}", + "localhost:50051", + ), + "files Key and Cert must be specified both", + ), + ( + ( + "localhost:50051", + "--transport=ssl", + "--sslcertfile={c_public}", + "--sslcafile={ca}", + "--sslkeyfile", + ), + "flag needs an argument: --sslkeyfile", + ), + ( + ( + "localhost:50051", + "--transport=ssl", + "--sslkeyfile={c_private}", + "--sslcafile={ca}", + "--sslcertfile", + ), + "flag needs an argument: --sslcertfile", + ), + ( + ( + "localhost:50051", + "--transport=ssl", + "--sslkeyfile={c_private}", + "--sslcertfile={c_public}", + "--sslcafile", + ), + "flag needs an argument: --sslcafile", + ), + ], +) + +def test_cli_arguments_fail(tt_cmd, certificates, args, error): + cmd = [str(tt_cmd), *AeonConnectCommand] + cmd += (a.format(**certificates) for a in args) + + print(f"Run: {' '.join(cmd)}") + result = run( + cmd, + stderr=STDOUT, + stdout=PIPE, + text=True, + ) + assert result.returncode != 0 + assert error in result.stdout