diff --git a/authority/authorize.go b/authority/authorize.go index 0c1c6f22..95698b49 100644 --- a/authority/authorize.go +++ b/authority/authorize.go @@ -282,8 +282,8 @@ func (a *Authority) authorizeRenew(cert *x509.Certificate) error { if isRevoked { return errs.Unauthorized("authority.authorizeRenew: certificate has been revoked", opts...) } - p, ok := a.provisioners.LoadByCertificate(cert) - if !ok { + p, err := a.LoadProvisionerByCertificate(cert) + if err != nil { return errs.Unauthorized("authority.authorizeRenew: provisioner not found", opts...) } if err := p.AuthorizeRenew(context.Background(), cert); err != nil { @@ -383,8 +383,8 @@ func (a *Authority) AuthorizeRenewToken(ctx context.Context, ott string) (*x509. return nil, errs.InternalServerErr(err, errs.WithMessage("error validating renew token")) } - p, ok := a.provisioners.LoadByCertificate(leaf) - if !ok { + p, err := a.LoadProvisionerByCertificate(leaf) + if err != nil { return nil, errs.Unauthorized("error validating renew token: cannot get provisioner from certificate") } if err := a.UseToken(ott, p); err != nil { diff --git a/authority/authorize_test.go b/authority/authorize_test.go index a7bec277..c399eac4 100644 --- a/authority/authorize_test.go +++ b/authority/authorize_test.go @@ -847,6 +847,29 @@ func TestAuthority_authorizeRenew(t *testing.T) { cert: fooCrt, } }, + "ok/from db": func(t *testing.T) *authorizeTest { + a := testAuthority(t) + a.db = &db.MockAuthDB{ + MIsRevoked: func(key string) (bool, error) { + return false, nil + }, + MGetCertificateData: func(serialNumber string) (*db.CertificateData, error) { + p, ok := a.provisioners.LoadByName("step-cli") + if !ok { + t.Fatal("provisioner step-cli not found") + } + return &db.CertificateData{ + Provisioner: &db.ProvisionerData{ + ID: p.GetID(), + }, + }, nil + }, + } + return &authorizeTest{ + auth: a, + cert: fooCrt, + } + }, } for name, genTestCase := range tests {