Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement spiffebundle.Bundle type #89

Merged
merged 5 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions v2/bundle/jwtbundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ func New(trustDomain spiffeid.TrustDomain) *Bundle {
}
}

// FromJWTKeys creates a new bundle from JWT public keys.
func FromJWTKeys(trustDomain spiffeid.TrustDomain, jwtKeys map[string]crypto.PublicKey) *Bundle {
return &Bundle{
trustDomain: trustDomain,
jwtKeys: jwtKeys,
}
}

// Load loads a bundle from a file on disk.
func Load(trustDomain spiffeid.TrustDomain, path string) (*Bundle, error) {
bundleBytes, err := ioutil.ReadFile(path)
Expand Down
12 changes: 11 additions & 1 deletion v2/bundle/jwtbundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ func TestNew(t *testing.T) {
require.Equal(t, td, b.TrustDomain())
}

func TestFromJWTKeys(t *testing.T) {
jwtKeys := map[string]crypto.PublicKey{
"key-1": "test-1",
"key-2": "test-2",
}
b := jwtbundle.FromJWTKeys(td, jwtKeys)
require.NotNil(t, b)
assert.Equal(t, b.JWTKeys(), jwtKeys)
}

func TestLoad(t *testing.T) {
testCases := []struct {
tf testFile
Expand Down Expand Up @@ -228,7 +238,7 @@ func TestMarshal(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, bundleBytesMarshal)

// Prase the marshaled bundle
// Parse the marshaled bundle
bundleParsed, err := jwtbundle.Parse(td, bundleBytesMarshal)
require.NoError(t, err)

Expand Down
Loading