Esempio n. 1
0
func TestPublicKeyParsing(t *testing.T) {
	padding := strings.Repeat("1", 256)
	for _, key := range []string{
		"ssh-rsa AAAA1234" + padding,
		"ssh-rsa AAAA1234" + padding + " [email protected]",
		"ssh-rsa AAAA1234" + padding + " other text",
		"ssh-rsa AAAA1234" + padding + "\n",
		"ssh-rsa AAAA1234" + padding + " other text\n",
	} {
		if !PublicKeyRegex.MatchString(key) {
			t.Errorf("'%v' is not a public key", key)
		}
	}
	for _, key := range []string{
		"ssh-rsa AAAA1234",
		"ssh-rsa AAAA1234" + " [email protected]",
		"ssh-rsa AAAA12!34" + " [email protected]",
	} {
		if PublicKeyRegex.MatchString(key) {
			t.Errorf("Expected failure for invalid key '%v'", key)
		}
	}
}