Commit b01bc6b2 authored by Denis Kuznetsov's avatar Denis Kuznetsov Committed by Commit Bot

Add more test with local policy test server.

1) PolicyTestServer can be configured not to ask for device attributes
during enrollment.
2) PolicyTestServer can be configured to produce specific HTTP error
codes during enrollment

Bug: 950471
Change-Id: Ie49080260bfc4d07ae46b3f64a72df750a09913d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1556804
Commit-Queue: Denis Kuznetsov <antrim@chromium.org>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#648697}
parent 318c3ed4
......@@ -7,12 +7,15 @@
#include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
#include "chrome/browser/chromeos/login/test/js_checker.h"
#include "chrome/browser/chromeos/login/test/test_predicate_waiter.h"
#include "ui/base/l10n/l10n_util.h"
namespace chromeos {
namespace test {
namespace ui {
const char kEnrollmentStepSignin[] = "signin";
const char kEnrollmentStepWorking[] = "working";
const char kEnrollmentStepSuccess[] = "success";
const char kEnrollmentStepError[] = "error";
const char kEnrollmentStepLicenses[] = "license";
......@@ -36,6 +39,7 @@ const char kLocation[] = "location";
namespace {
const char* const kAllSteps[] = {
ui::kEnrollmentStepSignin, ui::kEnrollmentStepWorking,
ui::kEnrollmentStepLicenses, ui::kEnrollmentStepDeviceAttributes,
ui::kEnrollmentStepSuccess, ui::kEnrollmentStepADJoin,
ui::kEnrollmentStepError, ui::kEnrollmentStepADJoinError};
......@@ -45,6 +49,9 @@ std::string StepVisibleExpression(const std::string& step) {
"').length > 0";
}
const std::initializer_list<base::StringPiece> kEnrollmentErrorRetryButtonPath =
{"oauth-enroll-error-card", "submitButton"};
} // namespace
EnrollmentUIMixin::EnrollmentUIMixin(InProcessBrowserTestMixinHost* host)
......@@ -76,6 +83,25 @@ void EnrollmentUIMixin::UseSelectedLicense() {
OobeJS().TapOnPath({"oauth-enroll-license-ui", "next"});
}
void EnrollmentUIMixin::ExpectErrorMessage(int error_message_id,
bool can_retry) {
const std::string element_path =
GetOobeElementPath({"oauth-enroll-error-card"});
const std::string message = OobeJS().GetString(element_path + ".textContent");
ASSERT_TRUE(std::string::npos !=
message.find(l10n_util::GetStringUTF8(error_message_id)));
if (can_retry) {
OobeJS().ExpectVisiblePath(kEnrollmentErrorRetryButtonPath);
} else {
OobeJS().ExpectHiddenPath(kEnrollmentErrorRetryButtonPath);
}
}
void EnrollmentUIMixin::RetryAfterError() {
OobeJS().TapOnPath(kEnrollmentErrorRetryButtonPath);
WaitForStep(ui::kEnrollmentStepSignin);
}
void EnrollmentUIMixin::SubmitDeviceAttributes(const std::string& asset_id,
const std::string& location) {
OobeJS().TypeIntoPath(asset_id, {"oauth-enroll-asset-id"});
......
......@@ -51,6 +51,9 @@ class EnrollmentUIMixin : public InProcessBrowserTestMixin {
void WaitForStep(const std::string& step);
bool IsStepDisplayed(const std::string& step);
void ExpectErrorMessage(int error_message_id, bool can_retry);
void RetryAfterError();
// Fills out the UI with device attribute information and submits it.
void SubmitDeviceAttributes(const std::string& asset_id,
const std::string& location);
......
......@@ -77,6 +77,19 @@ void LocalPolicyTestServerMixin::ExpectAvailableLicenseCount(int perpetual,
policy_test_server_->SetConfig(server_config_);
}
void LocalPolicyTestServerMixin::SetUpdateDeviceAttributesPermission(
bool allowed) {
server_config_.SetKey("allow_set_device_attributes", base::Value(allowed));
policy_test_server_->SetConfig(server_config_);
}
void LocalPolicyTestServerMixin::SetExpectedDeviceEnrollmentError(
int net_error_code) {
server_config_.SetKey("device_register_http_error",
base::Value(net_error_code));
policy_test_server_->SetConfig(server_config_);
}
bool LocalPolicyTestServerMixin::UpdateDevicePolicy(
const enterprise_management::ChromeDeviceSettingsProto& policy) {
DCHECK(policy_test_server_);
......
......@@ -39,6 +39,13 @@ class LocalPolicyTestServerMixin : public InProcessBrowserTestMixin {
// There should be at least one license type.
void ExpectAvailableLicenseCount(int perpetual, int annual, int kiosk);
void SetUpdateDeviceAttributesPermission(bool allowed);
// Configures server to respond with particular error code during device
// registration.
// |net_error_code| - error code from device_management_service.cc.
void SetExpectedDeviceEnrollmentError(int net_error_code);
// Set response for DeviceStateRetrievalRequest. Returns that if finds state
// key passed in the request. State keys could be set by RegisterClient call
// on policy test server.
......
......@@ -58,6 +58,8 @@ Example:
"token": "abcd-ef01-123123123",
"username": "admin@example.com"
},
"device_register_http_error" : 902,
"allow_set_device_attributes" : false,
}
"""
......@@ -427,6 +429,9 @@ class PolicyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
if not auth:
return (403, 'No authorization')
if 'device_register_http_error' in policy:
return (policy['device_register_http_error'], 'Preconfigured error')
if ('managed_users' not in policy):
return (500, 'Error in config - no managed users')
username = self.server.ResolveUser(auth)
......@@ -716,8 +721,15 @@ class PolicyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
A tuple of HTTP status code and response data to send to the client.
"""
response = dm.DeviceManagementResponse()
policy = self.server.GetPolicies()
update_allowed = True
if ('allow_set_device_attributes' in policy):
update_allowed = policy['allow_set_device_attributes']
response.device_attribute_update_permission_response.result = (
dm.DeviceAttributeUpdatePermissionResponse.ATTRIBUTE_UPDATE_ALLOWED)
dm.DeviceAttributeUpdatePermissionResponse.ATTRIBUTE_UPDATE_ALLOWED
if update_allowed else
dm.DeviceAttributeUpdatePermissionResponse.ATTRIBUTE_UPDATE_DISALLOWED)
return (200, response)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment