As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects

Passing pushauth flag as bool in json body to internal api doesn't become a...

Open Manoj Memana Jayakumar requested to merge mmj/gitlab-shell:506-jsandlin into main
2 files
+ 135
20
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -17,10 +17,10 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/internal/gitlabnet/twofactorverify"
)
func setup(t *testing.T) []testserver.TestRequestHandler {
func setupManual(t *testing.T) []testserver.TestRequestHandler {
requests := []testserver.TestRequestHandler{
{
Path: "/api/v4/internal/two_factor_otp_check",
Path: "/api/v4/internal/two_factor_manual_otp_check",
Handler: func(w http.ResponseWriter, r *http.Request) {
b, err := io.ReadAll(r.Body)
defer r.Body.Close()
@@ -54,12 +54,12 @@ func setup(t *testing.T) []testserver.TestRequestHandler {
}
const (
question = "OTP: \n"
errorHeader = "OTP validation failed.\n"
manualQuestion = "OTP: \n"
manualErrorHeader = "OTP validation failed.\n"
)
func TestExecute(t *testing.T) {
requests := setup(t)
func TestExecuteManual(t *testing.T) {
requests := setupManual(t)
url := testserver.StartSocketHttpServer(t, requests)
@@ -69,41 +69,35 @@ func TestExecute(t *testing.T) {
answer string
expectedOutput string
}{
{
desc: "When push is provided",
arguments: &commandargs.Shell{GitlabKeyId: "1"},
answer: "",
expectedOutput: question + "Push OTP validation successful. Git operations are now allowed.\n",
},
{
desc: "With a known key id",
arguments: &commandargs.Shell{GitlabKeyId: "1"},
answer: "123456\n",
expectedOutput: question + "OTP validation successful. Git operations are now allowed.\n",
expectedOutput: manualQuestion + "OTP validation successful. Git operations are now allowed.\n",
},
{
desc: "With bad response",
arguments: &commandargs.Shell{GitlabKeyId: "-1"},
answer: "123456\n",
expectedOutput: question + errorHeader + "Parsing failed\n",
expectedOutput: manualQuestion + manualErrorHeader + "Parsing failed\n",
},
{
desc: "With API returns an error",
arguments: &commandargs.Shell{GitlabKeyId: "error"},
answer: "yes\n",
expectedOutput: question + errorHeader + "error message\n",
expectedOutput: manualQuestion + manualErrorHeader + "error message\n",
},
{
desc: "With API fails",
arguments: &commandargs.Shell{GitlabKeyId: "broken"},
answer: "yes\n",
expectedOutput: question + errorHeader + "Internal API error (500)\n",
expectedOutput: manualQuestion + manualErrorHeader + "Internal API error (500)\n",
},
{
desc: "With missing arguments",
arguments: &commandargs.Shell{},
answer: "yes\n",
expectedOutput: question + errorHeader + "who='' is invalid\n",
expectedOutput: "\nPush " + manualErrorHeader + "who='' is invalid\n" +"OTP: ",
},
}
@@ -112,9 +106,6 @@ func TestExecute(t *testing.T) {
output := &bytes.Buffer{}
input := bytes.NewBufferString(tc.answer)
if tc.answer == "" { // pushauth test must not provide input otherwise it gets treated as a manual OTP
input.Reset()
}
cmd := &Command{
Config: &config.Config{GitlabUrl: url},
Loading