Skip to content

Commit

Permalink
Switch cert to tokenutil (#7037)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai authored Jul 1, 2019
1 parent 8a77445 commit 1b7a8ba
Show file tree
Hide file tree
Showing 3 changed files with 299 additions and 133 deletions.
59 changes: 59 additions & 0 deletions builtin/credential/cert/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"path/filepath"

"github.com/go-test/deep"
"github.com/hashicorp/go-sockaddr"

"golang.org/x/net/http2"
Expand Down Expand Up @@ -39,6 +40,7 @@ import (
logicaltest "github.com/hashicorp/vault/helper/testhelpers/logical"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/helper/certutil"
"github.com/hashicorp/vault/sdk/helper/tokenutil"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -1949,3 +1951,60 @@ func Test_Renew(t *testing.T) {
t.Fatal("expected error")
}
}

func TestBackend_CertUpgrade(t *testing.T) {
s := &logical.InmemStorage{}

config := logical.TestBackendConfig()
config.StorageView = s

ctx := context.Background()

b := Backend()
if b == nil {
t.Fatalf("failed to create backend")
}
if err := b.Setup(ctx, config); err != nil {
t.Fatal(err)
}

foo := &CertEntry{
Policies: []string{"foo"},
Period: time.Second,
TTL: time.Second,
MaxTTL: time.Second,
BoundCIDRs: []*sockaddr.SockAddrMarshaler{&sockaddr.SockAddrMarshaler{SockAddr: sockaddr.MustIPAddr("127.0.0.1")}},
}

entry, err := logical.StorageEntryJSON("cert/foo", foo)
if err != nil {
t.Fatal(err)
}
err = s.Put(ctx, entry)
if err != nil {
t.Fatal(err)
}

certEntry, err := b.Cert(ctx, s, "foo")
if err != nil {
t.Fatal(err)
}

exp := &CertEntry{
Policies: []string{"foo"},
Period: time.Second,
TTL: time.Second,
MaxTTL: time.Second,
BoundCIDRs: []*sockaddr.SockAddrMarshaler{&sockaddr.SockAddrMarshaler{SockAddr: sockaddr.MustIPAddr("127.0.0.1")}},
TokenParams: tokenutil.TokenParams{
TokenPolicies: []string{"foo"},
TokenPeriod: time.Second,
TokenTTL: time.Second,
TokenMaxTTL: time.Second,
TokenBoundCIDRs: []*sockaddr.SockAddrMarshaler{&sockaddr.SockAddrMarshaler{SockAddr: sockaddr.MustIPAddr("127.0.0.1")}},
},
}
if diff := deep.Equal(certEntry, exp); diff != nil {
t.Fatal(diff)
}
}
Loading

0 comments on commit 1b7a8ba

Please sign in to comment.