Ejemplo n.º 1
0
func (s *Stack) injectPasswords(vm map[string]interface{}, cred *Cred, passwordVar string) {
	pass, ok := vm["password"]
	if ok && pass != "" {
		return
	}

	count := 1
	if n, ok := vm["count"].(int); ok && n > 1 {
		count = n
	}

	passwords := make(map[string]string, count)

	for i := 0; i < count; i++ {
		pass := cred.Password
		if pass == "" {
			pass = sanitizePassword.Replace(utils.Pwgen(16))
		}

		passwords[strconv.Itoa(i)] = pass
	}

	vm["password"] = "******" + passwordVar + ", count.index)}"

	s.Builder.Template.Variable[passwordVar] = map[string]interface{}{
		"default": passwords,
	}
}
Ejemplo n.º 2
0
func TestPwgenChars(t *testing.T) {
	cases := []int{2, 4, 5, 7, 8, 20, 50}

	for _, n := range cases {
		t.Run(fmt.Sprintf("%d-character long password", n), func(t *testing.T) {
			pw := utils.Pwgen(n)

			t.Logf("%s", pw)

			if len(pw) != n {
				t.Fatalf("got len(pw)=%d, want %d", len(pw), n)
			}
		})
	}
}