Skip to content

Commit f9e80d2

Browse files
committed
vcsim: add ssoadmin GetTrustedCertificates method
Signed-off-by: Doug MacEachern <[email protected]>
1 parent 6ac4eab commit f9e80d2

File tree

4 files changed

+70
-47
lines changed

4 files changed

+70
-47
lines changed

simulator/simulator.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ func (s *Service) call(ctx *Context, method *Method) soap.HasFault {
140140

141141
if session == nil {
142142
switch method.Name {
143-
case "RetrieveServiceContent", "PbmRetrieveServiceContent", "Fetch", "List", "Login", "LoginByToken", "LoginExtensionByCertificate", "RetrieveProperties", "RetrievePropertiesEx", "CloneSession":
143+
case
144+
"Login", "LoginByToken", "LoginExtensionByCertificate", "CloneSession", // SessionManager
145+
"RetrieveServiceContent", "RetrieveInternalContent", "PbmRetrieveServiceContent", // ServiceContent
146+
"Fetch", "RetrieveProperties", "RetrievePropertiesEx", // PropertyCollector
147+
"List", // lookup service
148+
"GetTrustedCertificates": // ssoadmin
144149
// ok for now, TODO: authz
145150
default:
146151
fault := &types.NotAuthenticated{

ssoadmin/client.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2018-2024 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package ssoadmin
186

@@ -588,3 +576,16 @@ func (c *Client) UpdateLdapAuthnType(ctx context.Context, name string, auth type
588576
_, err := methods.UpdateLdapAuthnType(ctx, c, &req)
589577
return err
590578
}
579+
580+
func (c *Client) GetTrustedCertificates(ctx context.Context) ([]string, error) {
581+
req := types.GetTrustedCertificates{
582+
This: c.ServiceContent.ConfigurationManagementService,
583+
}
584+
585+
res, err := methods.GetTrustedCertificates(ctx, c, &req)
586+
if err != nil {
587+
return nil, err
588+
}
589+
590+
return res.Returnval, nil
591+
}

ssoadmin/client_test.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
/*
2-
Copyright (c) 2018-2023 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package ssoadmin_test
186

197
import (
208
"context"
9+
"fmt"
2110
"os"
2211
"testing"
2312

@@ -57,6 +46,22 @@ func TestClient(t *testing.T) {
5746
verifyClient(t, ctx, c)
5847
}, model)
5948
})
49+
t.Run("System.Anonymous methods", func(t *testing.T) {
50+
simulator.Test(func(ctx context.Context, client *vim25.Client) {
51+
c, err := ssoadmin.NewClient(ctx, client)
52+
require.NoError(t, err)
53+
54+
c.Jar = nil // session cookie will not be sent
55+
56+
_, err = c.FindUser(ctx, "testuser")
57+
require.Error(t, err) // NotAuthenticated
58+
59+
certs, err := c.GetTrustedCertificates(ctx)
60+
require.NoError(t, err)
61+
fmt.Println(certs[0])
62+
require.NotEmpty(t, certs)
63+
})
64+
})
6065
}
6166

6267
func verifyClient(t *testing.T, ctx context.Context, c *ssoadmin.Client) {
@@ -66,5 +71,4 @@ func verifyClient(t *testing.T, ctx context.Context, c *ssoadmin.Client) {
6671
user, err := c.FindUser(ctx, "testuser")
6772
require.NoError(t, err)
6873
require.Equal(t, &types.AdminUser{Id: types.PrincipalId{Name: "testuser", Domain: "vsphere.local"}, Kind: "person"}, user)
69-
7074
}

ssoadmin/simulator/simulator.go

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
/*
2-
Copyright (c) 2022-2023 VMware, Inc. All Rights Reserved.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
http://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// © Broadcom. All Rights Reserved.
2+
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3+
// SPDX-License-Identifier: Apache-2.0
164

175
package simulator
186

@@ -24,6 +12,7 @@ import (
2412
"github.com/vmware/govmomi/ssoadmin"
2513
"github.com/vmware/govmomi/ssoadmin/methods"
2614
"github.com/vmware/govmomi/ssoadmin/types"
15+
"github.com/vmware/govmomi/vim25"
2716
"github.com/vmware/govmomi/vim25/soap"
2817
vim "github.com/vmware/govmomi/vim25/types"
2918
)
@@ -111,6 +100,10 @@ type SessionManager struct {
111100
vim.ManagedObjectReference
112101
}
113102

103+
type ConfigurationManagementService struct {
104+
vim.ManagedObjectReference
105+
}
106+
114107
type IdentitySourceManagementService struct {
115108
vim.ManagedObjectReference
116109
}
@@ -161,6 +154,10 @@ func New(vc *simulator.Registry, u *url.URL) *simulator.Registry {
161154
ManagedObjectReference: content.SessionManager,
162155
})
163156

157+
r.Put(&ConfigurationManagementService{
158+
ManagedObjectReference: content.ConfigurationManagementService,
159+
})
160+
164161
r.Put(&IdentitySourceManagementService{
165162
ManagedObjectReference: content.IdentitySourceManagementService,
166163
})
@@ -246,6 +243,22 @@ func (s *SessionManager) Logout(ctx *simulator.Context, req *types.Logout) soap.
246243
}
247244
}
248245

246+
func (*ConfigurationManagementService) GetTrustedCertificates(ctx *simulator.Context, _ *types.GetTrustedCertificates) soap.HasFault {
247+
m := ctx.For(vim25.Path).Map.SessionManager()
248+
249+
var res []string
250+
251+
if m.TLSCert != nil {
252+
res = append(res, m.TLSCert())
253+
}
254+
255+
return &methods.GetTrustedCertificatesBody{
256+
Res: &types.GetTrustedCertificatesResponse{
257+
Returnval: res,
258+
},
259+
}
260+
}
261+
249262
func (s *IdentitySourceManagementService) Get(ctx *simulator.Context, _ *types.Get) soap.HasFault {
250263
sources := IdentitySources
251264
sources.All = nil

0 commit comments

Comments
 (0)