Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
Remote tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lholota committed May 23, 2023
1 parent 6056a07 commit a454219
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
gitref:
required: false
type: string
default: master
default: refs/heads/master
secrets:
sops_age_key:
required: true
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
- 4444:4444
- 7900:7900
shm_size: 4g
environment:
VNC_NO_PASSWORD: 1
dns:
- ${DNS1}
- ${DNS2}
24 changes: 20 additions & 4 deletions nightwatch.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,32 @@ module.exports = {
acceptInsecureCerts: true
}
},
"lab": {
"local:lab": {
globals: {
domainSuffix: "-lab.homecentr.one",
secretsFile: "secrets.lab.yml"
secretsFile: "secrets.lab.yml",
isRemote: false
}
},
"prod": {
"remote:lab": {
globals: {
domainSuffix: "-lab.homecentr.one",
secretsFile: "secrets.prod.yml"
secretsFile: "secrets.lab.yml",
isRemote: true
}
},
"local:prod": {
globals: {
domainSuffix: ".homecentr.one",
secretsFile: "secrets.prod.yml",
isRemote: false
}
},
"remote:prod": {
globals: {
domainSuffix: ".homecentr.one",
secretsFile: "secrets.prod.yml",
isRemote: true
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions nightwatch/assertions/isAadPermissionRejectedPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const { reusable } = require("./isAadErrorPage")
const isAadErrorPage = require("./isAadErrorPage")

exports.assertion = function () {
reusable(this, "AADSTS50105")
const reusable = function (context) {
isAadErrorPage.reusable("AADSTS50105", context)
}

const assertion = function () {
reusable(this)
};

module.exports = {
reusable,
assertion
}
39 changes: 39 additions & 0 deletions nightwatch/assertions/isCloudflarePermissionRejectedPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const reusable = function (context) {
context.formatMessage = () => {
const message = `Checking if the page ${this.negate ? 'doesn\'t indicate' : 'indicates'} cloudflare permission rejected`;

return {
message,
args: []
}
};

context.expected = () => {
return "That account does not have access."
}

context.value = function (result) {
return result.value;
};

context.failure = function (result) {
return !result;
};

context.evaluate = function (value) {
return value && value.startsWith(this.expected())
};

context.command = async function (callback) {
this.api.getText("div.AuthBox-messages", callback)
};
};

const assertion = function () {
reusable(this)
};

module.exports = {
reusable,
assertion
}
10 changes: 10 additions & 0 deletions nightwatch/assertions/isPermissionRejectedPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const isAadPermissionRejectedPage = require("./isAadPermissionRejectedPage")
const isCloudflarePermissionRejectedPage = require("./isCloudflarePermissionRejectedPage")

exports.assertion = function () {
if (this.__nightwatchInstance.settings.globals.isRemote) {
isCloudflarePermissionRejectedPage.reusable(this)
} else {
isAadPermissionRejectedPage.reusable(this)
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"client:local:prod": "env-cmd -f ./environments/local.prod.env docker-compose up --force-recreate --remove-orphans",
"client:remote:lab": "env-cmd -f ./environments/remote.lab.env docker-compose up --force-recreate --remove-orphans",
"client:remote:prod": "env-cmd -f ./environments/remote.prod.env docker-compose up --force-recreate --remove-orphans",
"test:local:lab": "nightwatch --skiptags remoteonly -e lab",
"test:local:prod": "nightwatch --skiptags remoteonly -e prod",
"test:remote:lab": "nightwatch --skiptags localonly -e lab",
"test:remove:prod": "nightwatch --skiptags localonly -e prod"
"test:local:lab": "nightwatch --skiptags remoteonly -e local:lab",
"test:local:prod": "nightwatch --skiptags remoteonly -e local:prod",
"test:remote:lab": "nightwatch --skiptags localonly -e remote:lab",
"test:remove:prod": "nightwatch --skiptags localonly -e remote:prod"
},
"devDependencies": {
"env-cmd": "^10.1.0",
Expand Down
27 changes: 26 additions & 1 deletion tests/argocd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
describe('Argo CD should', () => {
describe('Argo CD when accessed locally should', () => {
this.tags = [ "localonly" ]

afterEach((browser) => {
browser.end()
})
Expand All @@ -18,4 +20,27 @@ describe('Argo CD should', () => {
.signInAsNonAdmin()
.assert.isAadPermissionRejectedPage()
});
});

describe('Argo CD when accessed remotely should', () => {
this.tags = [ "remoteonly" ]

afterEach((browser) => {
browser.end()
})

it('Load main screen after signing in as admin', (browser) => {
browser
.subdomain('argocd')
.signInAsAdmin() // Sign into Cloudflare access
.click('a > button') // Redirects to AAD
.assert.textContains("div.sidebar__logo", "Argo CD")
});

it('Not allow non-admins to use the app', (browser) => {
browser
.subdomain('argocd')
.signInAsNonAdmin() // Sign into Cloudflare access
.assert.isCloudflarePermissionRejectedPage()
});
});
2 changes: 1 addition & 1 deletion tests/k8s-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ describe('Kubernetes dashboard should', () => {
browser
.subdomain('k8s')
.signInAsNonAdmin()
.assert.isAadPermissionRejectedPage()
.assert.isPermissionRejectedPage()
});
});
28 changes: 27 additions & 1 deletion tests/proxmox-ve.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
describe('Proxmox VE should', () => {
describe('Proxmox VE when accessed locally should', () => {
this.tags = [ "localonly" ]

afterEach((browser) => {
browser.end()
})
Expand All @@ -20,4 +22,28 @@ describe('Proxmox VE should', () => {
.signInAsNonAdmin()
.assert.isAadPermissionRejectedPage()
});
});

describe('Proxmox VE when accessed remotely should', () => {
this.tags = [ "remoteonly" ]

afterEach((browser) => {
browser.end()
})

it('Load main screen after signing in as admin', (browser) => {
browser
.subdomain('pve')
.signInAsAdmin() // Sign into Cloudflare Access
.setValue('#pveloginrealm-inputEl', 'Azure Active Directory')
.click('a#button-1070') // Redirects to AAD
.assert.textContains("#versioninfo-innerCt", "Virtual Environment")
});

it('Not allow non-admins to use the app', (browser) => {
browser
.subdomain('pve')
.signInAsNonAdmin() // Sign into Cloudflare Access
.assert.isCloudflarePermissionRejectedPage()
});
});

0 comments on commit a454219

Please sign in to comment.