Beispiel #1
0
// TestNewSignatureVerifierFromFile tests initializing SignatureVerifier from file
func TestNewSignatureVerifierFromFile(t *testing.T) {
	v, err := NewSignatureVerifierFromAuthorizedKeysFile(authorizedKeyFile)
	if err != nil {
		t.Fatal("Fail to read from authorized key file:", err)
	}

	keys := v.pubkeys
	if bytes.Compare(gossh.MarshalAuthorizedKey(keys[0]), []byte(firstAuthorizedKey)) != 0 {
		t.Fatal("Wrong first authorized key")
	}
	if bytes.Compare(gossh.MarshalAuthorizedKey(keys[1]), []byte(secondAuthorizedKey)) != 0 {
		t.Fatal("Wrong second authorized key")
	}
}
Beispiel #2
0
func TestMarshalParsePublicKey(t *testing.T) {
	pub := getTestPublicKey(t)

	authKeys := ssh.MarshalAuthorizedKey(pub)
	actualFields := strings.Fields(string(authKeys))
	if len(actualFields) == 0 {
		t.Fatalf("failed authKeys: %v", authKeys)
	}

	// drop the comment
	expectedFields := strings.Fields(keys["authorized_keys"])[0:2]

	if !reflect.DeepEqual(actualFields, expectedFields) {
		t.Errorf("got %v, expected %v", actualFields, expectedFields)
	}

	actPub, _, _, _, ok := ssh.ParseAuthorizedKey([]byte(keys["authorized_keys"]))
	if !ok {
		t.Fatalf("cannot parse %v", keys["authorized_keys"])
	}
	if !reflect.DeepEqual(actPub, pub) {
		t.Errorf("got %v, expected %v", actPub, pub)
	}
}