blob: 3ccba92d0e0ce6d2f56180ee763d2ee38602f8a2 [file] [log] [blame]
// 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 policy
import (
"context"
"time"
"chromiumos/tast/ctxutil"
"chromiumos/tast/remote/policyutil"
"chromiumos/tast/rpc"
ps "chromiumos/tast/services/cros/policy"
"chromiumos/tast/testing"
)
type testInfo struct {
username string // username for Chrome login
password string // password to login
dmserver string // device management server url
}
func init() {
testing.AddTest(&testing.Test{
Func: GAIAEnrollment,
LacrosStatus: testing.LacrosVariantUnneeded,
Desc: "GAIA Enroll a device without checking policies",
Contacts: []string{
"rzakarian@google.com", // Test author
"chromeos-commercial-remote-management@google.com",
},
Attr: []string{"group:dpanel-end2end"},
SoftwareDeps: []string{"reboot", "chrome"},
ServiceDeps: []string{"tast.cros.policy.PolicyService"},
Timeout: 7 * time.Minute,
Params: []testing.Param{
{
Name: "autopush",
Val: testInfo{
username: "policy.GAIAEnrollment.user_name",
password: "policy.GAIAEnrollment.password",
dmserver: "https://crosman-alpha.sandbox.google.com/devicemanagement/data/api",
},
},
},
Vars: []string{
"policy.GAIAEnrollment.user_name",
"policy.GAIAEnrollment.password",
},
})
}
func GAIAEnrollment(ctx context.Context, s *testing.State) {
param := s.Param().(testInfo)
username := s.RequiredVar(param.username)
password := s.RequiredVar(param.password)
dmServerURL := param.dmserver
defer func(ctx context.Context) {
if err := policyutil.EnsureTPMAndSystemStateAreResetRemote(ctx, s.DUT()); err != nil {
s.Error("Failed to reset TPM after test: ", err)
}
}(ctx)
ctx, cancel := ctxutil.Shorten(ctx, 3*time.Minute)
defer cancel()
if err := policyutil.EnsureTPMAndSystemStateAreResetRemote(ctx, s.DUT()); err != nil {
s.Fatal("Failed to reset TPM: ", err)
}
cl, err := rpc.Dial(ctx, s.DUT(), s.RPCHint())
if err != nil {
s.Fatal("Failed to connect to the RPC service on the DUT: ", err)
}
defer cl.Close(ctx)
pc := ps.NewPolicyServiceClient(cl.Conn)
if _, err := pc.GAIAEnrollAndLoginUsingChrome(ctx, &ps.GAIAEnrollAndLoginUsingChromeRequest{
Username: username,
Password: password,
DmserverURL: dmServerURL,
}); err != nil {
s.Fatal("Failed to enroll using chrome: ", err)
}
}