-
Notifications
You must be signed in to change notification settings - Fork 0
/
vdi_kiosk.go
234 lines (207 loc) · 6.77 KB
/
vdi_kiosk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// Copyright 2021 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package fixtures
import (
"context"
"time"
"chromiumos/tast/common/fixture"
"chromiumos/tast/common/policy"
"chromiumos/tast/common/policy/fakedms"
"chromiumos/tast/errors"
"chromiumos/tast/local/apps"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/uiauto/faillog"
"chromiumos/tast/local/input"
"chromiumos/tast/local/kioskmode"
"chromiumos/tast/local/policyutil/fixtures"
"chromiumos/tast/local/uidetection"
vdiApps "chromiumos/tast/local/vdi/apps"
"chromiumos/tast/local/vdi/apps/citrix"
"chromiumos/tast/local/vdi/apps/vmware"
"chromiumos/tast/testing"
)
func init() {
testing.AddFixture(&testing.Fixture{
Name: fixture.KioskCitrixLaunched,
Desc: "Starts DUT fake enrolled in Kiosk mode with Citrix application installed, started and logged in",
Contacts: []string{
"kamilszare@google.com",
"cros-engprod-muc@google.com",
},
Impl: &kioskFixtureState{
vdiApplicationToStart: apps.Citrix,
vdiConnector: &citrix.Connector{},
vdiServerKey: "vdi.citrix_url",
vdiUsernameKey: "vdi.citrix_username",
vdiPasswordKey: "vdi.citrix_password",
},
Vars: []string{
"vdi.citrix_url",
"vdi.citrix_username",
"vdi.citrix_password",
"uidetection.key_type",
"uidetection.key",
"uidetection.server",
},
SetUpTimeout: chrome.EnrollmentAndLoginTimeout + vdiApps.VDILoginTimeout,
ResetTimeout: chrome.ResetTimeout,
TearDownTimeout: chrome.ResetTimeout,
PostTestTimeout: 15 * time.Second,
Data: citrix.CitrixData,
Parent: fixture.FakeDMSEnrolled,
})
testing.AddFixture(&testing.Fixture{
Name: fixture.KioskVmwareLaunched,
Desc: "Starts DUT fake enrolled in Kiosk mode with Vmware application installed, started and logged in",
Contacts: []string{
"kamilszare@google.com",
"cros-engprod-muc@google.com",
},
Impl: &kioskFixtureState{
vdiApplicationToStart: apps.VMWare,
vdiConnector: &vmware.Connector{},
vdiServerKey: "vdi.vmware_url",
vdiUsernameKey: "vdi.vmware_username",
vdiPasswordKey: "vdi.vmware_password",
},
Vars: []string{
"vdi.vmware_url",
"vdi.vmware_username",
"vdi.vmware_password",
"uidetection.key_type",
"uidetection.key",
"uidetection.server",
},
SetUpTimeout: chrome.EnrollmentAndLoginTimeout + vdiApps.VDILoginTimeout,
ResetTimeout: chrome.ResetTimeout,
TearDownTimeout: chrome.ResetTimeout,
PostTestTimeout: 15 * time.Second,
Data: vmware.VmwareData,
Parent: fixture.FakeDMSEnrolled,
})
}
type kioskFixtureState struct {
// cr is a connection to an already-started Chrome instance that loads
// policies from FakeDMS.
cr *chrome.Chrome
// kiosk is a reference to a kiosk sessions providing a clean way to tear
// down the session.
kiosk *kioskmode.Kiosk
// vdiApplicationToStart is the VDI application that is launched.
vdiApplicationToStart apps.App
// VdiApplication
vdiConnector vdiApps.VDIInt
// vdiServerKey is a key to retrieve VDI server url.
vdiServerKey string
// vdiUsernameKey is a key to retrieve user name to access VDI app.
vdiUsernameKey string
// vdiPasswordKey is a key to retrieve VDI user password.
vdiPasswordKey string
// accountsConfiguration holds the Kiosk accounts configuration that is
// prepared in SetUp when creating Kiosk session and in TearDown when
// cleaning policies preventing Kiosk from autostart - since
// kioskmode.AutoLaunch() is used.
accountsConfiguration policy.DeviceLocalAccounts
}
func (v *kioskFixtureState) SetUp(ctx context.Context, s *testing.FixtState) interface{} {
fdms, ok := s.ParentValue().(*fakedms.FakeDMS)
if !ok {
s.Fatal("Parent is not a FakeDMS fixture")
}
vdiAccountID := "vdi_kiosk"
accountType := policy.AccountTypeKioskApp
kioskAppPolicy := policy.DeviceLocalAccountInfo{
AccountID: &vdiAccountID,
AccountType: &accountType,
KioskAppInfo: &policy.KioskAppInfo{
AppId: &v.vdiApplicationToStart.ID,
}}
v.accountsConfiguration = policy.DeviceLocalAccounts{
Val: []policy.DeviceLocalAccountInfo{
kioskAppPolicy,
},
}
kiosk, cr, err := kioskmode.New(
ctx,
fdms,
kioskmode.CustomLocalAccounts(&v.accountsConfiguration),
kioskmode.AutoLaunch(vdiAccountID),
)
if err != nil {
s.Error("Failed to start Chrome in kiosk mode: ", err)
}
ok = false
defer func(ctx context.Context) {
if !ok {
if err := kiosk.Close(ctx); err != nil {
s.Error("Failed to close kiosk: ", err)
}
}
}(ctx)
v.cr = cr
v.kiosk = kiosk
defer faillog.DumpUITreeWithScreenshotOnError(ctx, s.OutDir(), s.HasError, cr, "vdi_kiosk_fixt_ui_tree")
// Connect to Test API to use it with the UI library.
tconn, err := cr.TestAPIConn(ctx)
if err != nil {
s.Fatal("Failed to create Test API connection: ", err)
}
detector := uidetection.New(tconn,
s.RequiredVar("uidetection.key_type"),
s.RequiredVar("uidetection.key"),
s.RequiredVar("uidetection.server"))
v.vdiConnector.Init(s, detector)
kb, err := input.Keyboard(ctx)
if err != nil {
s.Fatal("Failed to get a keyboard")
}
defer kb.Close()
if err := v.vdiConnector.Login(
ctx,
kb,
&vdiApps.VDILoginConfig{
Server: s.RequiredVar(v.vdiServerKey),
Username: s.RequiredVar(v.vdiUsernameKey),
Password: s.RequiredVar(v.vdiPasswordKey),
}); err != nil {
s.Fatal("Was not able to login to the VDI application: ", err)
}
if err := v.vdiConnector.WaitForMainScreenVisible(ctx); err != nil {
s.Fatal("Main screen of the VDI application was not visible: ", err)
}
chrome.Lock()
ok = true
return &FixtureData{vdiConnector: v.vdiConnector, cr: cr, uidetector: detector, inKioskMode: true}
}
func (v *kioskFixtureState) TearDown(ctx context.Context, s *testing.FixtState) {
chrome.Unlock()
if v.cr == nil {
s.Fatal("Chrome not yet started")
}
if err := v.kiosk.Close(ctx); err != nil {
s.Error("Failed to close kiosk: ", err)
}
v.cr = nil
}
func (v *kioskFixtureState) Reset(ctx context.Context) error {
// Check the connection to Chrome.
if err := v.cr.Responded(ctx); err != nil {
return errors.Wrap(err, "existing Chrome connection is unusable")
}
// Check the main VDI screen is on.
if err := v.vdiConnector.WaitForMainScreenVisible(ctx); err != nil {
return errors.Wrap(err, "VDI main screen was not present")
}
return nil
}
func (v *kioskFixtureState) PreTest(ctx context.Context, s *testing.FixtTestState) {}
func (v *kioskFixtureState) PostTest(ctx context.Context, s *testing.FixtTestState) {
tconn, err := v.cr.TestAPIConn(ctx)
if err != nil {
s.Fatal("Failed to create TestAPI connection: ", err)
}
if err := dumpPolicies(ctx, tconn, fixtures.PolicyFileDump); err != nil {
s.Fatal("Could not store policies: ", err)
}
}