コード例 #1
0
ファイル: util.go プロジェクト: stevendanna/chef-load
func getPublicKey(privateKeyPath string) string {
	privateKey := getPrivateKey(privateKeyPath)
	rsaPrivateKey, _ := chef.PrivateKeyFromString([]byte(privateKey))
	rsaPublicKey := rsaPrivateKey.Public()
	PubASN1, _ := x509.MarshalPKIXPublicKey(rsaPublicKey)
	publicKey := string(pem.EncodeToMemory(&pem.Block{
		Type:  "PUBLIC KEY",
		Bytes: PubASN1,
	}))
	return publicKey
}
コード例 #2
0
func TestAuthenticateHeader(t *testing.T) {
	base, _ := url.Parse("https://localhost/")
	pkey, _ := chef.PrivateKeyFromString([]byte(privKey))

	chefClient := &chef.Client{
		BaseURL: base,
		Auth: &chef.AuthConfig{
			PrivateKey: pkey,
			ClientName: "testClient",
		},
	}

	req, err := chefClient.NewRequest("GET", "clients", nil)

	if err != nil {
		t.Errorf("failed to create chef client")
	}

	if err = AuthenticateHeader(pubKey, time.Duration(0), req); err != nil {
		t.Errorf("header authentication failed: %s", err.Error())
	}
}