Coder Social home page Coder Social logo

adobe / aio-lib-events Goto Github PK

View Code? Open in Web Editor NEW
5.0 25.0 14.0 212 KB

Adobe I/O Javascript SDK library for Adobe I/O Events APIs

Home Page: https://www.adobe.io

License: Apache License 2.0

JavaScript 100.00%
adobe-io adobeio io-events serverless opendev npm nodejs

aio-lib-events's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aio-lib-events's Issues

Incorrect implementation and test for function signatureUtils::fetchPublicKeyFromCloudFront

Function signatureUtils::fetchPublicKeyFromCloudFront:

/**
* Fetches public key using the cloud front public key url
*
* @param {*} publicKeyUrl - cloud front public key url of format
* https://static.adobeioevents.com/prod/keys/pub-key-<random-uuid>.pem
* @returns {string} public key
*/
async function fetchPublicKeyFromCloudFront (publicKeyUrl) {
let pubKey
await fetch(publicKeyUrl)
.then(response => response.text())
.then(text => {
logger.info('successfully fetched the public key %s from cloud front url %s', text, publicKeyUrl)
pubKey = text
})
.catch(error => {
logger.error('error fetching the public key from cloud front url %s due to => %s', publicKeyUrl, error.message)
return helpers.exportFunctions.genErrorResponse(500, error.message)
})
return pubKey
}

This is an odd use of both async/await and Promise.then, it works - but can be confusing for devs not used to it.

The then() clause assigns to a variable pubKey, which works in this case because of the await (if not pubKey would always be undefined), but it could just simply be the return value for the then(), and should therefore end up to be the return value of the await.

But the problematic item is the catch() clause. It returns helpers.exportFunctions.genErrorResponse(500, error.message), which has two problems:

  1. Since the return value of the await is not used, this return value will never be used.
  2. helpers.exportFunctions.genErrorResponse returns an object, and this function explicitly says it should return a string in the jsdoc. This is a mismatch.

This therefore renders the test "Test Fetch Key from CloudFront with Invalid Pub Key Url -> verify for invalid pub key" in signatureUtils.test.js as an invalid test since it will never throw an error. In fact the test is bogus (it passes but it is made to pass) - it doesn't really test the (mocked) return value - it tests an error that it sets up itself.

The test is here:

describe('Test Fetch Key from CloudFront with Invalid Pub Key Url', () => {
it('verify for invalid pub key', async () => {
const invalidCloudFrontUrl = undefined
fetch.mockImplementation(() => {
return Promise.resolve(Error)
})
await signatureUtils.fetchPublicKeyFromCloudFront(invalidCloudFrontUrl)
.then(res => {
throw new Error('invalid url')
})
.catch(e => {
// eslint-disable-next-line jest/no-conditional-expect
expect(e instanceof Error).toBe(true)
// eslint-disable-next-line jest/no-conditional-expect
expect(e.message).toEqual('invalid url')
})
})
})

Erroneous example for `getEventsObservableFromJournal` in README.md

README of the project includes an example for "Using the poller for journalling", which suggests invocation of .unsubscribe on object returned by RxJS' Observable.subscribe's returned by EventsCoreAPI.getEventsObservableFromJournal.

Expected Behaviour

journalling.unsubscribe should stop the stream of events being emitted after the timeout expires.

Actual Behaviour

  setTimeout(() => this.subscription.unsubscribe(), 1000)
                                     ^

TypeError: Cannot read property 'unsubscribe' of undefined
    at Timeout._onTimeout (/Users/ashishc/repo/aio-journal-consumer/journalConsumer.js:20:38)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7)

Reproduce Scenario (including but not limited to)

Execution of the sample-code for project README is sufficient to demonstrate the issue.

Steps to Reproduce

"Using the poller for journalling" sample-code from README, set a valid timeout and wait for that duration to pass after invocation of the code.

Platform and Version

macOS 10.15.4
node v13.13.0
npm v6.16.4

Sample Code that illustrates the problem

"Using the poller for journalling" sample-code from README

Logs taken while reproducing problem

N/A

Incorrect implementation and test for function signatureUtils::fetchPemEncodedPublicKeys

Function signatureUtils::fetchPemEncodedPublicKeys :

/**
* Feteched the pem encoded public keys either from the state lib cache or directly via cloud front url
*
* @param {*} pubKeyUrl1 cloud front url of format https://static.adobeioevents.com/prod/keys/pub-key-<random-uuid>.pem
* @param {*} pubKeyUrl2 cloud front url of format https://static.adobeioevents.com/prod/keys/pub-key-<random-uuid>.pem
* @returns {Array} of two public keys
*/
async function fetchPemEncodedPublicKeys (pubKeyUrl1, pubKeyUrl2) {
let pubKey1Pem, pubKey2Pem
try {
const state = await stateLib.init()
pubKey1Pem = await fetchPubKeyFromCacheOrApi(pubKeyUrl1, state)
pubKey2Pem = await fetchPubKeyFromCacheOrApi(pubKeyUrl2, state)
} catch (error) {
logger.error('error occurred while fetching pem encoded public keys either from cache or public key urls due to %s', error.message)
return helpers.exportFunctions.genErrorResponse(500, 'Error occurred while fetching pem encoded Public Key')
}
return [pubKey1Pem, pubKey2Pem]
}

The problematic item is the catch() clause. It returns helpers.exportFunctions.genErrorResponse(500, 'Error occurred while fetching pem encoded Public Key'), which has a problem:

  1. helpers.exportFunctions.genErrorResponse returns an object, and this function explicitly says it should return an Array of (two) strings (tuple).

This therefore renders the test "Test Fetch Pem Encoded Public Keys -> verify for invalid pub key url throws" in signatureUtils.test.js as an invalid test since it will never throw an error. In fact the test is bogus - it doesn't really test the (mocked) return value - it tests an error that it sets up itself.

The test is here:

describe('Test Fetch Pem Encoded Public Keys', () => {
it('verify for invalid pub key url throws', async () => {
const invalidCloudFrontUrl = undefined
fetch.mockImplementation(() => {
return Promise.resolve(Error)
})
await signatureUtils.fetchPemEncodedPublicKeys(invalidCloudFrontUrl)
.then(res => {
throw new Error('invalid url')
})
.catch(e => {
// eslint-disable-next-line jest/no-conditional-expect
expect(e instanceof Error).toBe(true)
// eslint-disable-next-line jest/no-conditional-expect
expect(e.message).toEqual('invalid url')
})
})
})

upcoming major version change to @adobe/aio-lib-core-networking

Description

This is to communicate an upcoming major version change to @adobe/aio-lib-core-networking to 2.0.0.
Your @adobe/aio-lib-core-networking version is ^1.0.0 and will not be affected by an npm install unless you manually change it to ^2.0.0

PR for discussion: adobe/aio-lib-core-networking#14

What Changed

The major change to take note if you upgrade, is the export of the library.
In 1.x.x the export of @adobe/aio-lib-core-networking returns an instance of the HttpExponentialBackoff class.
In 2.x.x the export of @adobe/aio-lib-core-networking returns an object, which contains the HttpExponentialBackoff class (which you need to instantiate).

Migration Example

1.x.x:

const fetchRetry = require('@adobe/aio-lib-core-networking')
fetchRetry.exponentialBackoff('http://example.com', {})

2.x.x:

const { HttpExponentialBackoff } = require('@adobe/aio-lib-core-networking')
const fetchRetry = new HttpExponentialBackoff()
fetchRetry.exponentialBackoff('http://example.com', {})

fix issues with jest/no-conditional-expect

Search for the text:
eslint-disable-next-line jest/no-conditional-expect

The disabling of these lines were temporary due to the eslint config upgrade. Using conditional expects do hide certain implementation issues or bad/incomplete tests.

index.test.js

  1. Get registration with retries -> Test for retries on 5xx response
  2. Publish event with retries -> Test for retries on 5xx response
  3. Fetch from journalling -> Fetch from journal with retries

signatureUtils.test.js

  1. Test Fetch Key from CloudFront with Invalid Pub Key Url -> verify for invalid pub key
  2. Test Fetch Pem Encoded Public Keys -> verify for invalid pub key url throws
  3. Test Get Key from Cache -> get key from cache throws

See #56, #57, and #58 before updating the tests.

Invalid test for function signatureUtils::getKeyFromCache

Function signatureUtils::getKeyFromCache :

/**
* Gets the public key from cache
*
* @param {*} state aio state lib instance
* @param {*} publicKeyFileNameAsKey public key file name in format pub-key-<random-uuid>.pem
* @returns {string} public key
*/
async function getKeyFromCache (state, publicKeyFileNameAsKey) {
try {
const keyObj = await state.get(publicKeyFileNameAsKey)
/**
* key json obj fetched from cache in below format
* {
* "value":"pem public key",
* "expiration":"24h timestamp"
* }
*/
return keyObj.value
} catch (error) {
logger.error('aio lib state get error due to => %s', error.message)
}
return null
}

On error, the function returns null, and never rethrows an Error.

The test "Test Get Key from Cache -> get key from cache throws" in signatureUtils.test.js is an invalid test since the tested function will never throw an error. In fact the test is bogus - it doesn't really test the return value or catch the function's error - it tests an error that it sets up itself.

The test is here:

describe('Test Get Key from Cache', () => {
it('get key from cache throws', async () => {
await signatureUtils.getKeyFromCache('state', 'invalid-url')
.then(res => {
throw new Error('lib state get error')
})
.catch(e => {
// eslint-disable-next-line jest/no-conditional-expect
expect(e instanceof Error).toBe(true)
// eslint-disable-next-line jest/no-conditional-expect
expect(e.message).toEqual('lib state get error')
})
})

An in-range update of eslint-plugin-jsdoc is breaking the build 🚨


🚨 Reminder! Less than one month left to migrate your repositories over to Snyk before Greenkeeper says goodbye on June 3rd! πŸ’œ πŸššπŸ’¨ πŸ’š

Find out how to migrate to Snyk at greenkeeper.io


The devDependency eslint-plugin-jsdoc was updated from 25.2.0 to 25.2.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-jsdoc is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Release Notes for v25.2.1

25.2.1 (2020-05-12)

Bug Fixes

  • check-param-names, require-param: check ExperimentalRestProperty from babel-eslint as with RestElement; fixes #536 (d330391)
Commits

The new version differs by 3 commits.

  • d330391 fix(check-param-names, require-param): check ExperimentalRestProperty from babel-eslint as with RestElement; fixes #536
  • aaae00e test(require-jsdoc): show exclusion of constructor
  • 87c6384 chore: bump regextras version

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.