Exemple #1
0
func TestCertsRm(t *testing.T) {
	if err := test.SetUpGitRepo(); err != nil {
		t.Error(err)
		return
	}
	if err := test.SetUpAssociation(); err != nil {
		t.Error(err)
		return
	}

	for _, data := range certRmTests {
		t.Logf("Data: %+v", data)
		if !data.expectErr {
			if output, err := test.RunCommand(test.BinaryName, []string{"-E", test.Alias, certsCreateCommandName, certsCreateSubcommandName, certName, pubKeyPath, privKeyPath}); err != nil {
				t.Errorf("Error creating cert: %s - %s", err, output)
				continue
			}
		}
		args := []string{"-E", data.env, certsRmCommandName, certsRmSubcommandName}
		if len(data.name) != 0 {
			args = append(args, data.name)
		}
		output, err := test.RunCommand(test.BinaryName, args)
		if err != nil != data.expectErr {
			t.Errorf("Unexpected error: %s", output)
			continue
		}
		if output != data.expectedOutput {
			t.Errorf("Expected: %s. Found: %s", data.expectedOutput, output)
			continue
		}
	}
}
Exemple #2
0
func TestCertsList(t *testing.T) {
	if err := test.SetUpGitRepo(); err != nil {
		t.Error(err)
		return
	}
	if err := test.SetUpAssociation(); err != nil {
		t.Error(err)
		return
	}

	for _, data := range certListTests {
		t.Logf("Data: %+v", data)
		args := []string{"-E", data.env}
		args = append(args, certsListCommandName, certsListSubcommandName)
		output, err := test.RunCommand(test.BinaryName, args)
		if err != nil != data.expectErr {
			t.Errorf("Unexpected error: %s", output)
			continue
		}
		if output != data.expectedOutput {
			t.Errorf("Expected: %s. Found: %s", data.expectedOutput, output)
			continue
		}
	}
}
Exemple #3
0
func TestCertsCreateTwice(t *testing.T) {
	if err := test.SetUpGitRepo(); err != nil {
		t.Error(err)
		return
	}
	if err := test.SetUpAssociation(); err != nil {
		t.Error(err)
		return
	}
	output, err := test.RunCommand(test.BinaryName, []string{"-E", test.Alias, certsCreateCommandName, certsCreateSubcommandName, certName, pubKeyPath, privKeyPath, "-s"})
	if err != nil {
		t.Errorf("Unexpected error: %s", output)
		return
	}
	if output != certsCreateStandardOutput {
		t.Errorf("Expected: %s. Found: %s", certsCreateStandardOutput, output)
		return
	}
	output, err = test.RunCommand(test.BinaryName, []string{"-E", test.Alias, certsCreateCommandName, certsCreateSubcommandName, certName, pubKeyPath, privKeyPath, "-s"})
	if err == nil {
		t.Errorf("Expected error but no error returned: %s", output)
		return
	}
	expectedOutput := "\033[31m\033[1m[fatal] \033[0m(92003) Cert Already Exists: A Cert already exists with the given name; alter name or delete existing cert to continue.\n"
	if output != expectedOutput {
		t.Errorf("Expected: %s. Found: %s", expectedOutput, output)
		return
	}
	if output, err = test.RunCommand(test.BinaryName, []string{"-E", test.Alias, certsRmCommandName, certsRmSubcommandName, certName}); err != nil {
		t.Errorf("Unexpected err: %s", output)
		return
	}
}
Exemple #4
0
func TestAssociated(t *testing.T) {
	if err := test.SetUpGitRepo(); err != nil {
		t.Error(err)
		t.Fail()
	}
	for _, data := range associatedTests {
		t.Logf("Data: %+v", data)
		if err := test.ClearAssociations(); err != nil {
			t.Error(err)
			continue
		}
		if data.associateFirst {
			if err := test.SetUpAssociation(); err != nil {
				t.Error(err)
				continue
			}
		}
		r := regexp.MustCompile(data.expectedOutput)
		output, err := test.RunCommand(test.BinaryName, []string{commandName})
		if err != nil != data.expectErr {
			t.Errorf("Unexpected error: %s", output)
			continue
		}
		if !r.MatchString(output) {
			t.Errorf("Expected: %s. Found: %s", data.expectedOutput, output)
			continue
		}
	}
}
Exemple #5
0
func TestCertsCreate(t *testing.T) {
	if err := test.SetUpGitRepo(); err != nil {
		t.Error(err)
		return
	}
	if err := test.SetUpAssociation(); err != nil {
		t.Error(err)
		return
	}

	for _, data := range certCreateTests {
		t.Logf("Data: %+v", data)
		args := []string{"-E", data.env, certsCreateCommandName, certsCreateSubcommandName}
		if len(data.name) != 0 {
			args = append(args, data.name)
		}
		if len(data.pubKeyPath) != 0 {
			args = append(args, data.pubKeyPath)
		}
		if len(data.privKeyPath) != 0 {
			args = append(args, data.privKeyPath)
		}
		if data.selfSigned {
			args = append(args, "-s")
		}
		if data.skipResolve {
			args = append(args, "--resolve=false")
		}
		output, err := test.RunCommand(test.BinaryName, args)
		if err != nil != data.expectErr {
			t.Errorf("Unexpected error: %s", output)
			continue
		}
		if output != data.expectedOutput {
			t.Errorf("Expected: %s. Found: %s", data.expectedOutput, output)
			continue
		}
		if err == nil {
			if output, err = test.RunCommand(test.BinaryName, []string{"-E", data.env, certsRmCommandName, certsRmSubcommandName, certName}); err != nil {
				t.Errorf("Unexpected err: %s", output)
				return
			}
		}
	}
}