Skip to content

Commit

Permalink
Use AuthorizationCrt and AuthorizationChain template variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraino committed Jan 3, 2022
1 parent b9132b1 commit f6bddce
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
20 changes: 10 additions & 10 deletions sshutil/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const (
InsecureKey = "Insecure"
UserKey = "User"
CertificateRequestKey = "CR"
CertificateKey = "Crt"
CertificateChainKey = "Chain"
AuthorizationCrtKey = "AuthorizationCrt"
AuthorizationChainKey = "AuthorizationChain"
)

// TemplateError represents an error in a template produced by the fail
Expand Down Expand Up @@ -136,16 +136,16 @@ func (t TemplateData) SetUserData(v interface{}) {
t.SetInsecure(UserKey, v)
}

// SetCertificate sets the given certificate in the template. This certificate
// is generally present in a token header.
func (t TemplateData) SetCertificate(crt interface{}) {
t.Set(CertificateKey, crt)
// SetAuthorizationCertificate sets the given certificate in the template. This
// certificate is generally present in a token header.
func (t TemplateData) SetAuthorizationCertificate(crt interface{}) {
t.Set(AuthorizationCrtKey, crt)
}

// SetCertificateChain sets a the given certificate chain in the template. These
// certificates are generally present in a token header.
func (t TemplateData) SetCertificateChain(chain interface{}) {
t.Set(CertificateChainKey, chain)
// SetAuthorizationCertificateChain sets a the given certificate chain in the
// template. These certificates are generally present in a token header.
func (t TemplateData) SetAuthorizationCertificateChain(chain interface{}) {
t.Set(AuthorizationChainKey, chain)
}

// SetCertificateRequest sets the simulated ssh certificate request the insecure
Expand Down
20 changes: 10 additions & 10 deletions sshutil/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func TestTemplateData_SetUserData(t *testing.T) {
}
}

func TestTemplateData_SetCertificate(t *testing.T) {
func TestTemplateData_SetAuthorizationCertificate(t *testing.T) {
crt1 := Certificate{Key: mustGeneratePublicKey(t)}
crt2 := Certificate{Key: mustGeneratePublicKey(t)}
type args struct {
Expand All @@ -454,31 +454,31 @@ func TestTemplateData_SetCertificate(t *testing.T) {
want TemplateData
}{
{"ok", TemplateData{}, args{crt1}, TemplateData{
CertificateKey: crt1,
AuthorizationCrtKey: crt1,
}},
{"overwrite", TemplateData{
CertificateKey: crt1,
AuthorizationCrtKey: crt1,
InsecureKey: TemplateData{
UserKey: "data",
},
}, args{crt2}, TemplateData{
CertificateKey: crt2,
AuthorizationCrtKey: crt2,
InsecureKey: TemplateData{
UserKey: "data",
},
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.t.SetCertificate(tt.args.crt)
tt.t.SetAuthorizationCertificate(tt.args.crt)
if !reflect.DeepEqual(tt.t, tt.want) {
t.Errorf("TemplateData.SetCertificate() = %v, want %v", tt.t, tt.want)
}
})
}
}

func TestTemplateData_SetCertificateChain(t *testing.T) {
func TestTemplateData_SetAuthorizationCertificateChain(t *testing.T) {
crt1 := Certificate{Key: mustGeneratePublicKey(t)}
crt2 := Certificate{Key: mustGeneratePublicKey(t)}
type args struct {
Expand All @@ -491,23 +491,23 @@ func TestTemplateData_SetCertificateChain(t *testing.T) {
want TemplateData
}{
{"ok", TemplateData{}, args{[]interface{}{crt1, crt2}}, TemplateData{
CertificateChainKey: []interface{}{crt1, crt2},
AuthorizationChainKey: []interface{}{crt1, crt2},
}},
{"overwrite", TemplateData{
CertificateChainKey: []interface{}{crt1, crt2},
AuthorizationChainKey: []interface{}{crt1, crt2},
InsecureKey: TemplateData{
UserKey: "data",
},
}, args{[]interface{}{crt1}}, TemplateData{
CertificateChainKey: []interface{}{crt1},
AuthorizationChainKey: []interface{}{crt1},
InsecureKey: TemplateData{
UserKey: "data",
},
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.t.SetCertificateChain(tt.args.crt)
tt.t.SetAuthorizationCertificateChain(tt.args.crt)
if !reflect.DeepEqual(tt.t, tt.want) {
t.Errorf("TemplateData.SetCertificate() = %v, want %v", tt.t, tt.want)
}
Expand Down
18 changes: 9 additions & 9 deletions x509util/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const (
InsecureKey = "Insecure"
UserKey = "User"
CertificateRequestKey = "CR"
CertificateKey = "Crt"
CertificateChainKey = "Chain"
AuthorizationCrtKey = "AuthorizationCrt"
AuthorizationChainKey = "AuthorizationChain"
)

// TemplateError represents an error in a template produced by the fail
Expand Down Expand Up @@ -89,16 +89,16 @@ func (t TemplateData) SetUserData(v interface{}) {
t.SetInsecure(UserKey, v)
}

// SetCertificate sets the given certificate in the template. This certificate
// SetAuthorizationCertificate sets the given certificate in the template. This certificate
// is generally present in a token header.
func (t TemplateData) SetCertificate(crt interface{}) {
t.Set(CertificateKey, crt)
func (t TemplateData) SetAuthorizationCertificate(crt interface{}) {
t.Set(AuthorizationCrtKey, crt)
}

// SetCertificateChain sets a the given certificate chain in the template. These
// certificates are generally present in a token header.
func (t TemplateData) SetCertificateChain(chain interface{}) {
t.Set(CertificateChainKey, chain)
// SetAuthorizationCertificateChain sets a the given certificate chain in the
// template. These certificates are generally present in a token header.
func (t TemplateData) SetAuthorizationCertificateChain(chain interface{}) {
t.Set(AuthorizationChainKey, chain)
}

// SetCertificateRequest sets the given certificate request in the insecure
Expand Down
20 changes: 10 additions & 10 deletions x509util/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestTemplateData_SetUserData(t *testing.T) {
}
}

func TestTemplateData_SetCertificate(t *testing.T) {
func TestTemplateData_SetAuthorizationCertificate(t *testing.T) {
crt1 := Certificate{DNSNames: []string{"crt1"}}
crt2 := Certificate{DNSNames: []string{"crt2"}}
type args struct {
Expand All @@ -239,31 +239,31 @@ func TestTemplateData_SetCertificate(t *testing.T) {
want TemplateData
}{
{"ok", TemplateData{}, args{crt1}, TemplateData{
CertificateKey: crt1,
AuthorizationCrtKey: crt1,
}},
{"overwrite", TemplateData{
CertificateKey: crt1,
AuthorizationCrtKey: crt1,
InsecureKey: TemplateData{
UserKey: "data",
},
}, args{crt2}, TemplateData{
CertificateKey: crt2,
AuthorizationCrtKey: crt2,
InsecureKey: TemplateData{
UserKey: "data",
},
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.t.SetCertificate(tt.args.crt)
tt.t.SetAuthorizationCertificate(tt.args.crt)
if !reflect.DeepEqual(tt.t, tt.want) {
t.Errorf("TemplateData.SetCertificate() = %v, want %v", tt.t, tt.want)
}
})
}
}

func TestTemplateData_SetCertificateChain(t *testing.T) {
func TestTemplateData_SetAuthorizationCertificateChain(t *testing.T) {
crt1 := Certificate{DNSNames: []string{"crt1"}}
crt2 := Certificate{DNSNames: []string{"crt2"}}
type args struct {
Expand All @@ -276,23 +276,23 @@ func TestTemplateData_SetCertificateChain(t *testing.T) {
want TemplateData
}{
{"ok", TemplateData{}, args{[]interface{}{crt1, crt2}}, TemplateData{
CertificateChainKey: []interface{}{crt1, crt2},
AuthorizationChainKey: []interface{}{crt1, crt2},
}},
{"overwrite", TemplateData{
CertificateChainKey: []interface{}{crt1, crt2},
AuthorizationChainKey: []interface{}{crt1, crt2},
InsecureKey: TemplateData{
UserKey: "data",
},
}, args{[]interface{}{crt1}}, TemplateData{
CertificateChainKey: []interface{}{crt1},
AuthorizationChainKey: []interface{}{crt1},
InsecureKey: TemplateData{
UserKey: "data",
},
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.t.SetCertificateChain(tt.args.crt)
tt.t.SetAuthorizationCertificateChain(tt.args.crt)
if !reflect.DeepEqual(tt.t, tt.want) {
t.Errorf("TemplateData.SetCertificate() = %v, want %v", tt.t, tt.want)
}
Expand Down

0 comments on commit f6bddce

Please sign in to comment.