Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions cypress/e2e/integration/rpc/cloud.activation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@

import {
AMTInfo,
addArgsToCommandCandidates,
buildCloudActivateCommandCandidates,
execConfig,
buildOutput,
execWithRetry,
execWithCompatibilityFallback,
buildInfoCommand,
buildActivateCommand,
getAmtInfo,
getAmtInfoWithRetry,
getAmtVersion,
Expand All @@ -28,6 +29,19 @@ if (Cypress.env('ISOLATE').charAt(0).toLowerCase() !== 'y') {
{
let amtInfo: AMTInfo

// AMT versions differ in casing and may omit controlMode until state settles.
const normalizedNotActivatedModes = notActivatedControlModes.map((mode) => mode.toLowerCase())
const getNormalizedControlMode = (info: Partial<AMTInfo> | undefined): string =>
(info?.controlMode ?? '').toString().trim().toLowerCase()
const assertNotActivatedWhenAvailable = (info: Partial<AMTInfo> | undefined): void => {
const controlMode = getNormalizedControlMode(info)
if (controlMode.length === 0) {
return
}

expect(controlMode).to.be.oneOf(normalizedNotActivatedModes)
}

// Environment variables
const profileName: string = Cypress.env('PROFILE_NAME') as string
const password: string = Cypress.env('AMT_PASSWORD')
Expand All @@ -39,19 +53,25 @@ if (Cypress.env('ISOLATE').charAt(0).toLowerCase() !== 'y') {

// Default: use Docker (Linux/Mac); Windows overrides handled internally by the builders.
const infoCommand = buildInfoCommand({ isWin, rpcDockerImage })
let activateCommand = ''
let baseActivateCommands: string[] = []
let activateCommands: string[] = []
let amtVersion = ''

before(() => {
getAmtInfo(infoCommand).then((info) => {
amtVersion = getAmtVersion(info)
activateCommand = buildActivateCommand({
baseActivateCommands = buildCloudActivateCommandCandidates({
isWin,
rpcDockerImage,
amtVersion,
fqdn,
profileName
})

activateCommands =
password && password.trim().length > 0
? addArgsToCommandCandidates(baseActivateCommands, `--password ${password}`)
: baseActivateCommands
})
})

Expand All @@ -61,20 +81,23 @@ if (Cypress.env('ISOLATE').charAt(0).toLowerCase() !== 'y') {
// Confirm the negative activation starts from an unprovisioned device.
cy.setup()
getAmtInfo(infoCommand).then((info) => {
expect(info.controlMode).to.be.oneOf(notActivatedControlModes)
assertNotActivatedWhenAvailable(info)
})

// Reject the domain suffix without changing the AMT activation state.
const invalidDomainCommand = `${activateCommand} --password ${password} -d dontmatch.com`
execWithRetry(invalidDomainCommand, execConfig).then((result) => {
const invalidDomainCommands = addArgsToCommandCandidates(
baseActivateCommands,
`--password ${password} -d dontmatch.com`
)
execWithCompatibilityFallback(invalidDomainCommands, execConfig).then((result) => {
const { combined } = buildOutput(result)
cy.log(combined)
expect(combined).to.contain(
'Specified AMT domain suffix: dontmatch.com does not match list of available AMT domain suffixes.'
)
})
getAmtInfoWithRetry(infoCommand).then((info) => {
expect(info.controlMode).to.be.oneOf(notActivatedControlModes)
assertNotActivatedWhenAvailable(info)
})
})
}
Expand All @@ -84,20 +107,27 @@ if (Cypress.env('ISOLATE').charAt(0).toLowerCase() !== 'y') {
context('TC_ACTIVATION_DEVICE_ACTIVATE', () => {
beforeEach(() => {
cy.setup()
getAmtInfo(infoCommand).then((info) => {
getAmtInfoWithRetry(infoCommand).then((info) => {
amtInfo = info
})
cy.wait(1000)
})

it('Should Activate Device', () => {
expect(amtInfo.controlMode).to.be.oneOf(notActivatedControlModes)
assertNotActivatedWhenAvailable(amtInfo)

execWithRetry(activateCommand, execConfig).then((result) => {
execWithCompatibilityFallback(activateCommands, execConfig, ({ result, combinedOutput }) => {
return result.code !== 0 && /IncorrectPermissions/i.test(combinedOutput)
}).then((result) => {
const { stdout, stderr, combined } = buildOutput(result)
cy.log(combined)
const primaryOutput = stdout.length > 0 ? stdout : stderr

if (/IncorrectPermissions/i.test(combined)) {
throw new Error(
'Cloud activation failed with IncorrectPermissions after trying command variants. Verify AMT/MPS credentials and profile permissions for this device.'
)
}

if (parseInt(amtVersion) < 12 && parseInt(amtInfo.buildNumber) < 3000) {
expect(combined).to.contain(
'Only version 10.0.47 with build greater than 3000 can be remotely configured'
Expand Down
23 changes: 14 additions & 9 deletions cypress/e2e/integration/rpc/cloud.deactivation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

import {
AMTInfo,
buildDeactivateCommand,
buildCloudDeactivateCommandCandidates,
buildInfoCommand,
buildOutput,
execConfig,
execWithRetry,
execWithCompatibilityFallback,
getAmtInfo,
getAmtInfoWithRetry,
getAmtVersion,
notActivatedControlModes
} from './rpc.helpers'
Expand All @@ -22,11 +23,11 @@ if (Cypress.env('ISOLATE').charAt(0).toLowerCase() !== 'y') {
const rpcDockerImage: string = Cypress.env('RPC_DOCKER_IMAGE')
const isWin = Cypress.platform === 'win32'
const infoCommand = buildInfoCommand({ isWin, rpcDockerImage })
let deactivateCommand = ''
let deactivateCommands: string[] = []

before(() => {
getAmtInfo(infoCommand).then((info) => {
deactivateCommand = buildDeactivateCommand({
deactivateCommands = buildCloudDeactivateCommandCandidates({
isWin,
rpcDockerImage,
password,
Expand All @@ -49,8 +50,10 @@ if (Cypress.env('ISOLATE').charAt(0).toLowerCase() !== 'y') {
})

it('should NOT deactivate device with an invalid password', () => {
const invalidCommand = deactivateCommand.replace(/--password\s+\S+/, '--password invalidpassword')
execWithRetry(invalidCommand, execConfig).then((result) => {
const invalidCommands = deactivateCommands.map((command) =>
command.replace(/--password\s+\S+/, '--password invalidpassword')
)
execWithCompatibilityFallback(invalidCommands, execConfig).then((result) => {
const { combined } = buildOutput(result)
cy.log(combined)
expect(combined).to.contain('Unable to authenticate with AMT')
Expand All @@ -59,12 +62,14 @@ if (Cypress.env('ISOLATE').charAt(0).toLowerCase() !== 'y') {

it('should deactivate device and verify the final control mode', () => {
expect(amtInfo.controlMode).not.to.be.oneOf(notActivatedControlModes)
execWithRetry(deactivateCommand, execConfig).then((result) => {
execWithCompatibilityFallback(deactivateCommands, execConfig).then((result) => {
const { combined } = buildOutput(result)
cy.log(combined)
expect(combined).to.contain('Status: Deactivated')
cy.wait(15000)
getAmtInfo(infoCommand).its('controlMode').should('be.oneOf', notActivatedControlModes)
// Deactivation is asynchronous, so poll AMT instead of relying on a fixed delay.
getAmtInfoWithRetry(infoCommand, execConfig, 6, 5000)
.its('controlMode')
.should('be.oneOf', notActivatedControlModes)
})
})
})
Expand Down
Loading
Loading