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
8 changes: 4 additions & 4 deletions e2e/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CONSOLEAPI_API_KEY=
CONSOLEAPI_ACCESS_TOKEN=
CONSOLEAPI_IMS_ORG_ID=
CONSOLEAPI_ENV=
CONSOLE_API_API_KEY=
CONSOLE_API_ACCESS_TOKEN=
CONSOLE_API_IMS_ORG_ID=
CONSOLE_API_ENV=
8 changes: 4 additions & 4 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

To run the e2e test you'll need these env variables set (copy `.env.example` to `.env`):

1. `CONSOLEAPI_API_KEY` (this is the same IMS client id used by the cli)
2. `CONSOLEAPI_ACCESS_TOKEN` (this is the access token retrieved by an `aio login`)
3. `CONSOLEAPI_IMS_ORG_ID` (get this from the App Builder project's `.aio` file)
4. `CONSOLEAPI_ENV` (`prod` (default) or `stage`)
1. `CONSOLE_API_API_KEY` (this is the same IMS client id used by the cli)
2. `CONSOLE_API_ACCESS_TOKEN` (this is the access token retrieved by an `aio login`)
3. `CONSOLE_API_IMS_ORG_ID` (get this from the App Builder project's `.aio` file)
4. `CONSOLE_API_ENV` (`prod` (default) or `stage`)

## Run

Expand Down
14 changes: 10 additions & 4 deletions e2e/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
// load .env values in the e2e folder, if any
require('dotenv').config({ path: path.join(__dirname, '.env') })

const missingEnvVars = ['CONSOLE_API_API_KEY', 'CONSOLE_API_ACCESS_TOKEN', 'CONSOLE_API_IMS_ORG_ID']
.filter(v => !process.env[v])
if (missingEnvVars.length > 0) {
throw new Error(`Missing required environment variables: ${missingEnvVars.join(', ')}`)
}

let sdkClient = {}
const apiKey = process.env.CONSOLEAPI_API_KEY
const accessToken = process.env.CONSOLEAPI_ACCESS_TOKEN
const imsOrgId = process.env.CONSOLEAPI_IMS_ORG_ID
const env = process.env.CONSOLEAPI_ENV || 'prod'
const apiKey = process.env.CONSOLE_API_API_KEY
const accessToken = process.env.CONSOLE_API_ACCESS_TOKEN
const imsOrgId = process.env.CONSOLE_API_IMS_ORG_ID
const env = process.env.CONSOLE_API_ENV || 'prod'

// these ids will be assigned when creating the project and workspace dynamically for the test
let fireflyProjectId, projectId, defaultWorkspaceId, workspaceId, orgId, fireflyWorkspaceId
Expand Down Expand Up @@ -395,7 +401,7 @@
describe('Enterprise credentials', () => {
// let credentialId, fromCredentialId

// test('createEnterpriseCredential API', async () => {

Check warning on line 404 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 404 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 404 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 404 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, windows-latest)

Some tests seem to be commented

Check warning on line 404 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, windows-latest)

Some tests seem to be commented

Check warning on line 404 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, windows-latest)

Some tests seem to be commented
// expect(orgId).toBeDefined()
// expect(projectId).toBeDefined()
// expect(workspaceId).toBeDefined()
Expand All @@ -410,7 +416,7 @@
// console.log('Entp integration created with Id: ', credentialId)
// })

// test('getCredentials API (service)', async () => {

Check warning on line 419 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 419 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 419 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 419 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, windows-latest)

Some tests seem to be commented

Check warning on line 419 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, windows-latest)

Some tests seem to be commented

Check warning on line 419 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, windows-latest)

Some tests seem to be commented
// expect(credentialId).toBeDefined() // if not, createEnterpriseIntegration test failed
// expect(orgId).toBeDefined()
// expect(projectId).toBeDefined()
Expand All @@ -428,7 +434,7 @@
// expect(res.body[0].integration_type).toEqual('service')
// })

// test('getSDKProperties', async () => {

Check warning on line 437 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 437 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 437 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 437 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, windows-latest)

Some tests seem to be commented

Check warning on line 437 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, windows-latest)

Some tests seem to be commented

Check warning on line 437 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, windows-latest)

Some tests seem to be commented
// expect(orgId).toBeDefined()
// expect(fromCredentialId).toBeDefined()
//
Expand All @@ -439,7 +445,7 @@
// expect(res.statusText).toBe('OK')
// })

// test('subscribeCredentialToServices API (AdobeIOManagementAPISDK)', async () => {

Check warning on line 448 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 448 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 448 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 448 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, windows-latest)

Some tests seem to be commented

Check warning on line 448 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, windows-latest)

Some tests seem to be commented

Check warning on line 448 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, windows-latest)

Some tests seem to be commented
// expect(credentialId).toBeDefined() // if not, createEnterpriseIntegration test failed
// expect(orgId).toBeDefined()
// expect(projectId).toBeDefined()
Expand All @@ -460,7 +466,7 @@
// expect(res.body).toEqual({ sdkList: [sdkCode] })
// })

// test('downloadWorkspaceJson API', async () => {

Check warning on line 469 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 469 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 469 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 469 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, windows-latest)

Some tests seem to be commented

Check warning on line 469 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, windows-latest)

Some tests seem to be commented

Check warning on line 469 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, windows-latest)

Some tests seem to be commented
// expect(credentialId).toBeDefined() // if not, createEnterpriseIntegration test failed
// expect(orgId).toBeDefined()
// expect(projectId).toBeDefined()
Expand All @@ -482,7 +488,7 @@

// organization integration APIs on workspace credentials

// test('getIntegration API', async () => {

Check warning on line 491 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 491 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 491 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 491 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, windows-latest)

Some tests seem to be commented

Check warning on line 491 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, windows-latest)

Some tests seem to be commented

Check warning on line 491 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, windows-latest)

Some tests seem to be commented
// expect(credentialId).toBeDefined() // if not, createEnterpriseIntegration test failed
// expect(orgId).toBeDefined()
// const res = await sdkClient.getIntegration(orgId, credentialId)
Expand All @@ -494,7 +500,7 @@
// expect(res.body.type).toEqual('entp')
// })

// test('getIntegrationSecrets API', async () => {

Check warning on line 503 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 503 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 503 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 503 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, windows-latest)

Some tests seem to be commented

Check warning on line 503 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, windows-latest)

Some tests seem to be commented

Check warning on line 503 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, windows-latest)

Some tests seem to be commented
// expect(credentialId).toBeDefined() // if not, createEnterpriseIntegration test failed
// expect(orgId).toBeDefined()
// const res = await sdkClient.getIntegrationSecrets(orgId, credentialId)
Expand All @@ -505,7 +511,7 @@
// expect(res.body.client_secrets).toBeDefined()
// })

// test('uploadAndBindCertificate API', async () => {

Check warning on line 514 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 514 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 514 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 514 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, windows-latest)

Some tests seem to be commented

Check warning on line 514 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, windows-latest)

Some tests seem to be commented

Check warning on line 514 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, windows-latest)

Some tests seem to be commented
// expect(credentialId).toBeDefined() // if not, createEnterpriseIntegration test failed
//
// expect(orgId).toBeDefined()
Expand All @@ -520,7 +526,7 @@
// })

// delete
// test('deleteCredential API (integrationType: entp)', async () => {

Check warning on line 529 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 529 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 529 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 529 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, windows-latest)

Some tests seem to be commented

Check warning on line 529 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, windows-latest)

Some tests seem to be commented

Check warning on line 529 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, windows-latest)

Some tests seem to be commented
// expect(credentialId).toBeDefined() // if not, createEnterpriseIntegration test failed
// expect(orgId).toBeDefined()
// expect(projectId).toBeDefined()
Expand Down Expand Up @@ -567,7 +573,7 @@
expect(res.body[0].integration_type).toEqual('oauthwebapp')
})

// test('subscribeCredentialToServices API (Adobe Stock)', async () => {

Check warning on line 576 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 576 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 576 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, ubuntu-latest)

Some tests seem to be commented

Check warning on line 576 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (20.x, windows-latest)

Some tests seem to be commented

Check warning on line 576 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (24.x, windows-latest)

Some tests seem to be commented

Check warning on line 576 in e2e/e2e.js

View workflow job for this annotation

GitHub Actions / build / build (22.x, windows-latest)

Some tests seem to be commented
// expect(credentialId).toBeDefined() // if not, createAdobeIdCredential test failed
// expect(orgId).toBeDefined()
// expect(projectId).toBeDefined()
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
"@adobe/aio-lib-core-logging": "^3",
"@adobe/aio-lib-core-networking": "^5.0.2",
"@adobe/aio-lib-env": "^3",
"axios": "^1.7.9",
"form-data": "^4.0.1",
"swagger-client": "^3.31.0"
},
"devDependencies": {
Expand Down
28 changes: 17 additions & 11 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ governing permissions and limitations under the License.
*/
const loggerNamespace = '@adobe/aio-lib-console'
const logger = require('@adobe/aio-lib-core-logging')(loggerNamespace, { provider: 'debug', level: process.env.LOG_LEVEL || 'debug' })
const axios = require('axios')
const FormData = require('form-data')

/**
* Reduce an Error to a string
Expand Down Expand Up @@ -118,33 +116,41 @@ function responseInterceptor (res) {
}

/**
* Use axios lib to directly call console API to create credential
* Use fetch to directly call console API to create credential
*
* @param {string} url URL string
* @param {string} accessToken Token to call the API
* @param {string} apiKey Api key
* @param {object} certificate A Readable stream with certificate content. eg: fs.createReadStream()
* @param {string} name Credential name
* @param {string} description Credential description
* @returns {object} The response object
* @returns {Promise<Response>} The response object
*/
async function createCredentialDirect (url, accessToken, apiKey, certificate, name, description) {
const chunks = []
for await (const chunk of certificate) {
chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)
}
const data = new FormData()
data.append('certificate', certificate)
data.append('certificate', new Blob([Buffer.concat(chunks)]), 'certificate')
data.append('name', name)
data.append('description', description)

const config = {
method: 'post',
url,
const res = await fetch(url, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + accessToken,
'content-type': 'multipart/form-data',
'x-api-key': apiKey
},
data
body: data
})
if (!res.ok) {
const body = await res.text()
const err = new Error(`${res.status} ${res.statusText}`)
err.response = { status: res.status, statusText: res.statusText, body, headers: Object.fromEntries(res.headers) }
throw err
}
return await axios.request(config)
return res
}

module.exports = {
Expand Down
53 changes: 46 additions & 7 deletions test/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ governing permissions and limitations under the License.
*/
const AioLogger = require('@adobe/aio-lib-core-logging')
const helpers = require('../src/helpers')
const axios = require('axios')
jest.mock('axios')
const stream = require('stream')
const mockedStream = new stream.Readable()
mockedStream._read = function (size) { /* do nothing */ }
Expand Down Expand Up @@ -162,18 +160,59 @@ describe('responseInterceptor', () => {
})

describe('createCredentialDirect', () => {
let fetchSpy
beforeEach(() => {
axios.mockReset()
fetchSpy = jest.spyOn(global, 'fetch').mockResolvedValue({ ok: true, status: 200 })
})
afterEach(() => {
fetchSpy.mockRestore()
})
test('API call', async () => {
const url = 'mockurl'
const accessToken = 'mockToken'
const apiKey = 'mockKey'
const name = 'mockName'
const desc = 'mock description'
axios.request.mockImplementation(() => Promise.resolve({ data: {} }))
const ret = await helpers.createCredentialDirect(url, accessToken, apiKey, mockedStream, name, desc)
expect(axios.request).toHaveBeenCalled()
expect(ret).toEqual({ data: {} })
const certStream = stream.Readable.from(Buffer.from('cert-data'))
const ret = await helpers.createCredentialDirect(url, accessToken, apiKey, certStream, name, desc)
expect(fetchSpy).toHaveBeenCalledWith(url, expect.objectContaining({
method: 'POST',
headers: expect.objectContaining({
Authorization: 'Bearer mockToken',
'x-api-key': 'mockKey'
})
}))
expect(ret).toEqual({ ok: true, status: 200 })
})
test('API call with string chunks', async () => {
const url = 'mockurl'
const accessToken = 'mockToken'
const apiKey = 'mockKey'
const name = 'mockName'
const desc = 'mock description'
const certStream = stream.Readable.from('cert-data-string')
const ret = await helpers.createCredentialDirect(url, accessToken, apiKey, certStream, name, desc)
expect(fetchSpy).toHaveBeenCalled()
expect(ret).toEqual({ ok: true, status: 200 })
})
test('throws on non-2xx response', async () => {
fetchSpy.mockResolvedValue({
ok: false,
status: 401,
statusText: 'Unauthorized',
text: jest.fn().mockResolvedValue('{"error":"unauthorized"}'),
headers: new Headers({ 'x-request-id': 'req-123' })
})
const certStream = stream.Readable.from(Buffer.from('cert-data'))
await expect(helpers.createCredentialDirect('mockurl', 'mockToken', 'mockKey', certStream, 'mockName', 'mock description'))
.rejects.toMatchObject({
message: '401 Unauthorized',
response: {
status: 401,
statusText: 'Unauthorized',
body: '{"error":"unauthorized"}',
headers: { 'x-request-id': 'req-123' }
}
})
})
})
Loading