Skip to content

Commit

Permalink
standalone: add test for dashboard with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
AjBreidenbach committed Jun 26, 2024
1 parent b5b46f2 commit 6f51883
Show file tree
Hide file tree
Showing 27 changed files with 350 additions and 87 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ jobs:
run: git clone --recurse-submodules --branch $UNFURL_BRANCH --single-branch --depth 1 https://github.com/onecommons/unfurl $HOME/unfurl; pip install -e $HOME/unfurl
- name: Integration test
run: yarn integration-test run --namespace onecommons/blueprints -- -e GENERATE_SUBDOMAINS=true --browser chrome -s cypress/e2e/blueprints/aws__baserow__baserow.cy.js
- name: pkill
run: pkill unfurl || /bin/true
- name: Integration test (staging upstream)
run: yarn integration-test run --namespace onecommons/blueprints -- -e GENERATE_SUBDOMAINS=true --browser chrome -s cypress/e2e/blueprints/aws__baserow__baserow.cy.js
env:
OC_INVITE_CODE: ${{ secrets.OC_INVITE_CODE }}
UNFURL_PACKAGE_RULES: 'gitlab.com/* staging.unfurl.cloud/* unfurl.cloud/* staging.unfurl.cloud/*'
UNFURL_CLOUD_SERVER: https://staging.unfurl.cloud
- name: Upload Cypress screenshots
if: ${{ failure() }}
uses: actions/upload-artifact@v2
Expand Down
2 changes: 2 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ module.exports = (on, config) => {

config.env.DEFAULT_NAMESPACE = config.env.DEFAULT_NAMESPACE || config.env.OC_IMPERSONATE

if(!config.env.DASHBOARD_DEST) config.env.DASHBOARD_DEST = ''

const
DIGITALOCEAN_DNS_ZONE = config.env.DIGITALOCEAN_DNS_ZONE || 'untrusted.me',
GCP_DNS_ZONE = config.env.GCP_DNS_ZONE,
Expand Down
5 changes: 3 additions & 2 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const MOCK_DEPLOY = Cypress.env('UNFURL_MOCK_DEPLOY') || Cypress.env('MOCK_DEPLO
const INTEGRATION_TEST_ARGS = Cypress.env('INTEGRATION_TEST_ARGS')
const UNFURL_SERVER_URL = Cypress.env('UNFURL_SERVER_URL')
const UNFURL_VALIDATION_MODE = Cypress.env('UNFURL_VALIDATION_MODE') || Cypress.env('VALIDATION_MODE')
const DASHBOARD_DEST = Cypress.env('DASHBOARD_DEST')

function whenUnfurlGUI(cb) {
cy.window().then(win => {
Expand Down Expand Up @@ -102,7 +103,7 @@ function login(username, password, impersonate) {
cy.url().should('not.contain', 'admin')

if(INTEGRATION_TEST_ARGS.dashboardRepo) {
cy.visit(`/${impersonate}/dashboard`)
cy.visit(`/${DASHBOARD_DEST}`)
}
}
}
Expand Down Expand Up @@ -150,7 +151,7 @@ function login(impersonateUser) {
}
win.sessionStorage['unfurl-trace'] = 't'
})
cy.visit(`/${impersonateUser || USERNAME}/dashboard`)
cy.visit(`/${DASHBOARD_DEST}`)
},
{
cacheAcrossSpecs: false,
Expand Down
40 changes: 30 additions & 10 deletions cypress/support/create-aws-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const AWS_DNS_TYPE = Cypress.env('AWS_DNS_TYPE')
const AWS_DEFAULT_REGION = Cypress.env('AWS_DEFAULT_REGION')
const USERNAME = Cypress.env('OC_IMPERSONATE')
const DASHBOARD_DEST = Cypress.env('DASHBOARD_DEST')
const STANDALONE_UNFURL = Cypress.env('STANDALONE_UNFURL')
const UNFURL_TEST_TMPDIR = Cypress.env('UNFURL_TEST_TMPDIR')

const createEnvironmentButton = () => cy.contains('button', 'Create New Environment', {timeout: BASE_TIMEOUT * 2})
const ENVIRONMENT_NAME_INPUT = '[data-testid="environment-name-input"]'
Expand Down Expand Up @@ -69,23 +71,41 @@ Cypress.Commands.add('createAWSEnvironment', (options) => {
options
)

let environmentCreated
let viewingEnv

cy.whenEnvironmentAbsent(environmentName, () => {
cy.visit(`/${DASHBOARD_DEST}/-/environments`)
createEnvironmentButton().click()
cy.awsCompleteEnvironmentDialog({environmentName})
cy.url().should('include', environmentName)
cy.awsAuthenticateEnvironment({region: AWS_DEFAULT_REGION})
cy.contains(environmentName).should('exist')
cy.contains('Amazon Web Services').should('exist')
environmentCreated = true
if(STANDALONE_UNFURL) {
const UNFURL_TEST_TMPDIR = Cypress.env('UNFURL_TEST_TMPDIR')
cy.execLoud(`testing-shared/ufhome-add-environment.sh aws "${UNFURL_TEST_TMPDIR}/ufsv" "${environmentName}"`)

cy.wait(1000)

cy.window().then(win => {
cy.request({
method: 'POST',
url: `/clear_project_file_cache?auth_project=${win.gon.home_project}`
})
})

cy.reload()
} else {
cy.visit(`/${DASHBOARD_DEST}/-/environments`)
createEnvironmentButton().click()
cy.awsCompleteEnvironmentDialog({environmentName})
cy.url().should('include', environmentName)
cy.awsAuthenticateEnvironment({region: AWS_DEFAULT_REGION})
cy.contains(environmentName).should('exist')
cy.contains('Amazon Web Services').should('exist')
viewingEnv = true
}
})

cy.environmentShouldExist(environmentName)

// create external resource
if (shouldCreateExternalResource) {
cy.whenInstancesAbsent(environmentName, () => {
environmentCreated || cy.visit(`/${DASHBOARD_DEST}/-/environments/${environmentName}`)
viewingEnv || cy.visit(`/${DASHBOARD_DEST}/-/environments/${environmentName}`)
if(shouldCreateDNS) {
cy.uncheckedCreateDNS(AWS_DNS_TYPE, AWS_DNS_ZONE)
}
Expand Down
8 changes: 5 additions & 3 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ before(() => {
cy.url().should('not.contain', 'admin')

if(INTEGRATION_TEST_ARGS.dashboardRepo) {
cy.visit(`/${IMPERSONATE}/dashboard`)
cy.visit(`/${DASHBOARD_DEST}`)
}
}
} else if (GENERATED_PASSWORD && IMPERSONATE) {
Expand All @@ -115,7 +115,7 @@ before(() => {
}

if(INTEGRATION_TEST_ARGS.dashboardRepo) {
cy.visit(`/${IMPERSONATE}/dashboard`)
cy.visit(`/${DASHBOARD_DEST}`)
}
}
})
Expand All @@ -141,9 +141,11 @@ beforeEach(() => {
cy.document().then(doc => {
const csrf = doc.querySelector('meta[name="csrf-token"]')?.content

const win = doc.parentView || doc.defaultView

cy.request({
method: 'PATCH',
url: `/${DASHBOARD_DEST}/-/variables`,
url: `/${DASHBOARD_DEST || win.gon.home_project}/-/variables`,
failOnStatusCode: false,
headers: {
'X-CSRF-Token': csrf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default {
'getUsername'
]),
disableDeployButton() {
return this.getUsername && !this.environmentsAreReady
return (window.gon.unfurl_gui || this.getUsername) && !this.environmentsAreReady
}
},
}
Expand Down
6 changes: 3 additions & 3 deletions scripts/src/add-project-member.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ async function addProjectMember(o) {
await login()


const matchingUsers = (await axios.get(`${process.env.OC_URL}/-/autocomplete/users.json?search=${username}`)).data
const matchingUsers = (await axios.get(`${process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL}/-/autocomplete/users.json?search=${username}`)).data

const user_id = `${matchingUsers.find(u => u.username == username).id}` // ffs gitlab

const url = `${process.env.OC_URL}/${project}/-/project_members`
const url = `${process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL}/${project}/-/project_members`
const page = (await axios.get(url)).data
const authenticity_token = extractCsrf(page)


const invitationUrl = `${process.env.OC_URL}/api/v4/projects/${encodeURIComponent(project)}/invitations`
const invitationUrl = `${process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL}/api/v4/projects/${encodeURIComponent(project)}/invitations`
const body = {
user_id,
format: 'json',
Expand Down
4 changes: 2 additions & 2 deletions scripts/src/create-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let authenticity_token
async function createEnvironment(o) {
if(!o) throw new Error('expected options to create new environment')
await login()
const environmentURL = `${process.env.OC_URL}/${o['project-path']}/-/environments`
const environmentURL = `${process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL}/${o['project-path']}/-/environments`
const res = await axios.get(environmentURL)
authenticity_token = extractCsrf(res.data)
const form = new FormData()
Expand Down Expand Up @@ -77,7 +77,7 @@ async function main() {
query: "mutation UpdateDeploymentObject($fullPath: ID!, $patch: JSON!, $path: String!) {\n updateDeploymentObj(input: {projectPath: $fullPath, patch: $patch, path: $path}) {\n isOk\n errors\n __typename\n }\n}\n"
}

const {data} = await axios.post(`${process.env.OC_URL}/api/graphql`, payload, {headers: {'X-CSRF-Token': authenticity_token}})
const {data} = await axios.post(`${process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL}/api/graphql`, payload, {headers: {'X-CSRF-Token': authenticity_token}})
if(data.errors && data.errors.length) throw new Error(data.errors[0].message)
}
}
13 changes: 8 additions & 5 deletions scripts/src/create-project-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ async function createProjectToken(o) {
const {project, accessLevel} = o
await login()

const url = `${process.env.OC_URL}/${project}/-/settings/access_tokens`
const url = `${process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL}/${project}/-/settings/access_tokens`
const page = (await axios.get(url)).data
const authenticity_token = extractCsrf(page)

const form = new FormData()

const FIELD_NAME = process.env.GITLAB_VERSION == '14.9'?
'resource_access_token': 'project_access_token'
// const FIELD_NAME = process.env.GITLAB_VERSION == '14.9'?
// 'resource_access_token': 'project_access_token'
const FIELD_NAME = 'resource_access_token'

form.append('authenticity_token', authenticity_token)
form.append(`${FIELD_NAME}[name]`, 'UNFURL_PROJECT_TOKEN')
Expand All @@ -37,7 +38,7 @@ async function createProjectToken(o) {
/*
* can't use API with admin user session?
* I'll try again later with a CSRF token
const url = `${process.env.OC_URL}/api/v4/projects/${encodeURIComponent(project)}/access_tokens`
const url = `${process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL}/api/v4/projects/${encodeURIComponent(project)}/access_tokens`
const response = await axios.post(
url,
{
Expand All @@ -51,8 +52,10 @@ async function createProjectToken(o) {
const status = response.status

if(status < 400 && status >= 200) {
if(response.data.new_token) {
return response.data.new_token
}
const token = response.data.match(/input.*name="created-personal-access-token.*value="((\w|-)+)"/)[1]
console.log({token})
return token
} else {
console.error(response)
Expand Down
30 changes: 20 additions & 10 deletions scripts/src/create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const OC_USERNAME = process.env.OC_USERNAME
const OC_PASSWORD = process.env.OC_PASSWORD
const OC_URL = process.env.OC_URL
const UNFURL_CLOUD_SERVER = process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL
const OC_INVITE_CODE = process.env.OC_INVITE_CODE

const {spawnSync} = require('child_process')

Expand All @@ -11,11 +12,12 @@ const axios = require('./shared/axios-instance.js')
const FormData = require('form-data')
const login = require('./shared/login.js')
const pushLocalRepo = require('./push-local-repo.js')
const fs = require('fs')

async function createUserAsAdmin(o) {
if(!o) throw new Error('expected options to create new user')
await login()
const res = await axios.get(`${OC_URL}/admin/users/new`)
const res = await axios.get(`${UNFURL_CLOUD_SERVER}/admin/users/new`)
const authenticity_token = extractCsrf(res.data)
const options = {
name: o.name || o.username,
Expand All @@ -38,19 +40,23 @@ async function createUserAsAdmin(o) {
"Content-Length": form.getLengthSync()
}

const status = (await axios.post(`${OC_URL}/admin/users`, form, {headers})).status
const status = (await axios.post(`${UNFURL_CLOUD_SERVER}/admin/users`, form, {headers})).status

return status < 400 && status >= 200
}

async function createUserBySignup(o) {
const selectRole = o.hasOwnProperty('select_role') || o.hasOwnProperty('select-role')
const inviteCode = o.invite_code || o['invite-code']
const inviteCode = o.invite_code || o['invite-code'] || OC_INVITE_CODE

if(!inviteCode) {
throw new Error('No invite code')
}

const username = o.username || o.name
{
const signupPage = await axios.get(`${OC_URL}/users/sign_up`)
const signupPage = await axios.get(`${UNFURL_CLOUD_SERVER}/users/sign_up`)
const authenticity_token = extractCsrf(signupPage.data)
const username = o.username || o.name

const data = {
'authenticity_token': authenticity_token,
Expand All @@ -65,7 +71,7 @@ async function createUserBySignup(o) {

spawnSync('sleep', ['2'])

await axios.get(`${OC_URL}/users/${username}/exists}`)
await axios.get(`${UNFURL_CLOUD_SERVER}/users/${username}/exists`)

const form = new FormData()

Expand All @@ -78,15 +84,15 @@ async function createUserBySignup(o) {

spawnSync('sleep', ['5'])

const response = (await axios.post(`${OC_URL}/users`, form, {headers}))
const response = (await axios.post(`${UNFURL_CLOUD_SERVER}/users`, form, {headers}))
if(response.status > 400) {
console.error(response.data)
return false
}
}

if(selectRole){
const welcomePage = await axios.get(`${OC_URL}/users/sign_up/welcome`)
const welcomePage = await axios.get(`${UNFURL_CLOUD_SERVER}/users/sign_up/welcome`)
const authenticity_token = extractCsrf(welcomePage.data)

const external = o.external
Expand All @@ -103,11 +109,15 @@ async function createUserBySignup(o) {
"Content-Length": form.getLengthSync()
}

const response = (await axios.post(`${OC_URL}/users/sign_up/welcome`, form, {headers}))
const response = (await axios.post(`${UNFURL_CLOUD_SERVER}/users/sign_up/welcome`, form, {headers}))
fs.writeFileSync('/tmp/sign_up.html', response.data, 'utf-8')
if(response.status > 400) {
console.error(response.data)
return false
}

const {exists} = (await axios.get(`${UNFURL_CLOUD_SERVER}/users/${username}/exists`))?.data
return !!exists
}

return true
Expand Down
4 changes: 2 additions & 2 deletions scripts/src/delete-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const login = require('./shared/login.js')

async function deleteProject(projectPath) {
await login()
const res = await axios.get(`${process.env.OC_URL}/admin/projects`)
const res = await axios.get(`${process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL}/admin/projects`)
const authenticity_token = extractCsrf(res.data)

const form = new FormData()
Expand All @@ -21,7 +21,7 @@ async function deleteProject(projectPath) {
"Content-Length": form.getLengthSync()
}

const status = (await axios.post(`${process.env.OC_URL}/admin/projects/${projectPath}`, form, {headers})).status
const status = (await axios.post(`${process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL}/admin/projects/${projectPath}`, form, {headers})).status

console.log(status)
return status < 400 && status >= 200
Expand Down
4 changes: 2 additions & 2 deletions scripts/src/fixture-from-deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const args = require('minimist')(process.argv.slice(2))
const deploymentName = args.deployment || args['deployment-name']
const username = args.username
const dashboard = args.dashboard || (args.username && `${args.username}/dashboard`)
const unfurlServer = args.unfurlServer || args['unfurl-server'] || `${process.env.OC_URL}/services/unfurl-server`
const unfurlServer = args.unfurlServer || args['unfurl-server'] || `${process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL}/services/unfurl-server`
// const generateTest = args['test-name'] || args['test'] || args['generate-test']
const fixtureName = args.fixtureName || args['fixture-name'] || args['test']
const fixturePath = `generated/deployments/${TEST_VERSIONS}/${fixtureName}`
Expand All @@ -29,7 +29,7 @@ async function main() {
}
})

await login(process.env.OC_URL, process.env.OC_USERNAME, process.env.OC_PASSWORD)
await login(process.env.UNFURL_CLOUD_SERVER || process.env.OC_URL, process.env.OC_USERNAME, process.env.OC_PASSWORD)
const response = await axios.get(
`${unfurlServer}/export?format=environments&branch=main&auth_project=${encodeURIComponent(dashboard)}&include_all_deployments=1`,
{
Expand Down
5 changes: 3 additions & 2 deletions scripts/src/forwarded-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@
"SKIP_NESTEDCLOUD",
"DASHBOARD_DEST",
"UNFURL_CMD",
"FAIL_FAST_ENABLED"
]
"FAIL_FAST_ENABLED",
"UNFURL_CLOUD_SERVER"
]
Loading

0 comments on commit 6f51883

Please sign in to comment.