-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aeneas Rekkas (arekkas)
committed
Jun 13, 2017
1 parent
b5cb0c6
commit 1fee2b3
Showing
10 changed files
with
264 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package jwk | ||
|
||
import ( | ||
"crypto/rand" | ||
"io" | ||
"testing" | ||
|
||
"github.com/ory/hydra/pkg" | ||
"github.com/pkg/errors" | ||
"github.com/square/go-jose" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func RandomBytes(n int) ([]byte, error) { | ||
bytes := make([]byte, n) | ||
if _, err := io.ReadFull(rand.Reader, bytes); err != nil { | ||
return []byte{}, errors.WithStack(err) | ||
} | ||
return bytes, nil | ||
} | ||
|
||
func TestHelperManagerKey(m Manager, keys *jose.JsonWebKeySet) func(t *testing.T) { | ||
pub := keys.Key("public") | ||
priv := keys.Key("private") | ||
|
||
return func(t *testing.T) { | ||
_, err := m.GetKey("faz", "baz") | ||
assert.NotNil(t, err) | ||
|
||
err = m.AddKey("faz", First(priv)) | ||
assert.Nil(t, err) | ||
|
||
got, err := m.GetKey("faz", "private") | ||
assert.Nil(t, err) | ||
assert.Equal(t, priv, got.Keys) | ||
|
||
err = m.AddKey("faz", First(pub)) | ||
assert.Nil(t, err) | ||
|
||
got, err = m.GetKey("faz", "private") | ||
assert.Nil(t, err) | ||
assert.Equal(t, priv, got.Keys) | ||
|
||
got, err = m.GetKey("faz", "public") | ||
assert.Nil(t, err) | ||
assert.Equal(t, pub, got.Keys) | ||
|
||
err = m.DeleteKey("faz", "public") | ||
assert.Nil(t, err) | ||
|
||
_, err = m.GetKey("faz", "public") | ||
assert.NotNil(t, err) | ||
} | ||
} | ||
|
||
func TestHelperManagerKeySet(m Manager, keys *jose.JsonWebKeySet) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
_, err := m.GetKeySet("foo") | ||
pkg.AssertError(t, true, err) | ||
|
||
err = m.AddKeySet("bar", keys) | ||
assert.Nil(t, err) | ||
|
||
got, err := m.GetKeySet("bar") | ||
assert.Nil(t, err) | ||
assert.Equal(t, keys.Key("public"), got.Key("public")) | ||
assert.Equal(t, keys.Key("private"), got.Key("private")) | ||
|
||
err = m.DeleteKeySet("bar") | ||
assert.Nil(t, err) | ||
|
||
_, err = m.GetKeySet("bar") | ||
assert.NotNil(t, err) | ||
} | ||
} |
Oops, something went wrong.