|
|
@@ -212,6 +212,7 @@ type mockAuthority struct {
|
|
|
checkSSHHost func(ctx context.Context, principal, token string) (bool, error)
|
|
|
getSSHBastion func(ctx context.Context, user string, hostname string) (*authority.Bastion, error)
|
|
|
version func() authority.Version
|
|
|
+ capabilities func() authority.Capabilities
|
|
|
}
|
|
|
|
|
|
func (m *mockAuthority) GetCertificateRevocationList() ([]byte, error) {
|
|
|
@@ -405,6 +406,13 @@ func (m *mockAuthority) Version() authority.Version {
|
|
|
return m.ret1.(authority.Version)
|
|
|
}
|
|
|
|
|
|
+func (m *mockAuthority) Capabilities() authority.Capabilities {
|
|
|
+ if m.version != nil {
|
|
|
+ return m.capabilities()
|
|
|
+ }
|
|
|
+ return m.ret1.(authority.Capabilities)
|
|
|
+}
|
|
|
+
|
|
|
func TestNewCertificate(t *testing.T) {
|
|
|
cert := parseCertificate(rootPEM)
|
|
|
if !reflect.DeepEqual(Certificate{Certificate: cert}, NewCertificate(cert)) {
|
|
|
@@ -873,6 +881,35 @@ func Test_Health(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func Test_Capabilities(t *testing.T) {
|
|
|
+ capResp := CapabilitiesResponse{
|
|
|
+ RequireClientAuthentication: false,
|
|
|
+ RemoteConfigurationManagement: true,
|
|
|
+ }
|
|
|
+ mockMustAuthority(t, &mockAuthority{ret1: authority.Capabilities(capResp)})
|
|
|
+ req := httptest.NewRequest("GET", "http://example.com/capabilities", nil)
|
|
|
+ w := httptest.NewRecorder()
|
|
|
+ Capabilities(w, req)
|
|
|
+
|
|
|
+ res := w.Result()
|
|
|
+ if res.StatusCode != 200 {
|
|
|
+ t.Errorf("caHandler.Capabilities StatusCode = %d, wants 200", res.StatusCode)
|
|
|
+ }
|
|
|
+
|
|
|
+ body, err := io.ReadAll(res.Body)
|
|
|
+ res.Body.Close()
|
|
|
+ if err != nil {
|
|
|
+ t.Errorf("caHandler.Capabilities unexpected error = %v", err)
|
|
|
+ }
|
|
|
+ wantBytes, err := json.Marshal(capResp)
|
|
|
+ if err != nil {
|
|
|
+ assert.FatalError(t, err)
|
|
|
+ }
|
|
|
+ if !bytes.Equal(bytes.TrimSpace(body), wantBytes) {
|
|
|
+ t.Errorf("caHandler.Capabilities Body = %s, wants %s", body, wantBytes)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func Test_Root(t *testing.T) {
|
|
|
tests := []struct {
|
|
|
name string
|