mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-31 01:47:33 +02:00
* hpke: add hpke package * Update pkg/hpke/url.go Co-authored-by: bobby <1544881+desimone@users.noreply.github.com> * Update pkg/hpke/url.go Co-authored-by: bobby <1544881+desimone@users.noreply.github.com> * Update pkg/hpke/url.go Co-authored-by: bobby <1544881+desimone@users.noreply.github.com> * gofmt Co-authored-by: bobby <1544881+desimone@users.noreply.github.com>
37 lines
895 B
Go
37 lines
895 B
Go
package hpke
|
|
|
|
import (
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestEncryptURLValues(t *testing.T) {
|
|
k1, err := GeneratePrivateKey()
|
|
require.NoError(t, err)
|
|
k2, err := GeneratePrivateKey()
|
|
require.NoError(t, err)
|
|
|
|
encrypted, err := EncryptURLValues(k1, k2.PublicKey(), url.Values{
|
|
"a": {"b", "c"},
|
|
"x": {"y", "z"},
|
|
})
|
|
assert.NoError(t, err)
|
|
assert.True(t, encrypted.Has(ParamSenderPublicKey))
|
|
assert.True(t, encrypted.Has(ParamQuery))
|
|
|
|
assert.True(t, IsEncryptedURL(encrypted))
|
|
|
|
encrypted.Set("extra", "value")
|
|
encrypted.Set("a", "notb")
|
|
senderPublicKey, decrypted, err := DecryptURLValues(k2, encrypted)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, url.Values{
|
|
"a": {"b", "c"},
|
|
"x": {"y", "z"},
|
|
"extra": {"value"},
|
|
}, decrypted)
|
|
assert.Equal(t, k1.PublicKey().String(), senderPublicKey.String())
|
|
}
|