diff --git a/.eslintignore b/.eslintignore index bd07d4e1..aa4b435f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ node_modules /dist +/scripts diff --git a/CHANGELOG.md b/CHANGELOG.md index 7618a353..1fce8bd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 3.0.11 + +### Bug Fixes + +- [#150](https://github.com/okta/okta-react/pull/150) fixes issue with displaying error in `LoginCallback` + # 3.0.10 ### Bug Fixes diff --git a/package.json b/package.json index d3fdd368..1c748592 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@okta/okta-react", - "version": "3.0.10", + "version": "3.0.11", "description": "React support for Okta", "private": true, "scripts": { @@ -12,6 +12,7 @@ "lint:report": "eslint -f checkstyle -o ./test-reports/lint/eslint-checkstyle-result.xml .", "prepare": "yarn build", "start": "yarn --cwd test/e2e/harness start", + "pretest:e2e": "node ./scripts/update-se-drivers.js", "test": "yarn lint && yarn test:unit && yarn test:e2e", "test:e2e": "yarn --cwd test/e2e/harness test", "test:unit": "jest" @@ -52,6 +53,7 @@ "@babel/plugin-transform-runtime": "^7.11.5", "@babel/preset-env": "^7.11.5", "@babel/preset-react": "^7.10.4", + "axios": "^0.21.0", "babel-jest": "^26.3.0", "babel-plugin-transform-inline-environment-variables": "^0.4.3", "chalk": "^4.1.0", diff --git a/scripts/travis.sh b/scripts/travis.sh index 6a4f36e9..96ad068f 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -1,6 +1,7 @@ set -e # if this build was triggered via a cron job, run tests on sauce labs if [ "${TRAVIS_EVENT_TYPE}" = "cron" ] ; then + yarn pretest yarn test:e2e else # run the lint, unit and e2e tests (on chrome headless) diff --git a/scripts/update-se-drivers.js b/scripts/update-se-drivers.js new file mode 100644 index 00000000..840842cf --- /dev/null +++ b/scripts/update-se-drivers.js @@ -0,0 +1,41 @@ +const axios = require('axios'); +const { execSync } = require('child_process'); + +function getOS() { + let os = process.platform; + if (os === 'darwin') { + os = 'MacOS'; + } else if (os === 'win32' || os === 'win64') { + os = 'Windows'; + } else if (os === 'linux') { + os = 'Linux'; + } + return os; +} + +const os = getOS(); +console.log(`Operating System - ${os}`); + +let chromeVersion; +if (os === 'MacOS') { + const chromeVersionString = execSync('/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --version').toString(); + // Get the major and minor version of the chrome version using regex (1 or more digits followed by a dot followed by 1 or more digits) + const matchIndex = 0; + chromeVersion = chromeVersionString.match(/(\d+(\.\d+)?)/)[matchIndex]; +} else { + chromeVersion = execSync('google-chrome --product-version').toString(); +} + +const chromeMajorVersion = chromeVersion.split('.')[0]; +console.log(`Chrome Major Version - ${chromeMajorVersion}`); + +const chromeDriverUrl = `https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${chromeMajorVersion}`; + +axios.get(chromeDriverUrl).then((response) => { + const chromeDriverVersion = response.data; + console.log(`Chrome Driver Version - ${chromeDriverVersion}`); + + execSync(`${__dirname}/../node_modules/protractor/bin/webdriver-manager update --versions.chrome ${chromeDriverVersion} --gecko false --versions.standalone latest`); +}).catch((err) => { + console.log(err); +}); diff --git a/scripts/update_se_drivers.sh b/scripts/update_se_drivers.sh deleted file mode 100755 index 4e35cb8a..00000000 --- a/scripts/update_se_drivers.sh +++ /dev/null @@ -1,174 +0,0 @@ -#! /bin/bash - -SCRIPT_PATH=$(dirname $(which $0)) -SCRIPT_DIR="${SCRIPT_PATH%scripts}" -DIR_MARKER="../" -DEFAULT_STANDALONE_VER=latest -DEFAULT_CHROME_DRIVER_VER=2.46 -#NODE_MODULES="${PWD}/node_modules" -NODE_MODULES="$SCRIPT_PATH/../node_modules" -DEPTH=$1 - -function setCallDepth() { - if [[ -z ${DEPTH} ]]; - then - DEPTH=$(echo "${SCRIPT_DIR}" | awk -F"${DIR_MARKER}" '{print NF-1}') - fi -} - -function setTargetPath() { - setCallDepth - if [[ ${DEPTH} > 0 ]]; - then - TARGET_PATH=$(for i in $(seq ${DEPTH}); do echo -n ${DIR_MARKER}; done) - else - TARGET_PATH=./ - fi -} - -function getOs() { - # MacOS or Linux? - sw_vers 2>/dev/null - RETVAL=$? - if [[ ${RETVAL} == 0 ]]; - then - OS=mac - else - OS=*nix - fi - echo "OS: ${OS}" -} - -function getChromeVersion() { - getOs - # chrome version - if [[ ${OS} == "mac" ]]; - then - TEMP_CHROME_VER=$(/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version) - else - TEMP_CHROME_VER=$(google-chrome --product-version) - fi - echo "Chrome Version: ${TEMP_CHROME_VER}" - CHROME_VER=$(echo ${TEMP_CHROME_VER} | sed -En 's/[^0-9]*([0-9]+)\..*/\1/p') - echo "Chrome Version: ${CHROME_VER}" -} - -function setChromeDriverVersion() { - if [[ -z ${CHROME_DRIVER_VER} ]]; - then - getChromeVersion - - # Chrome Version to chromedriver mapping - case $CHROME_VER in - 69) - CHROME_DRIVER_VER=2.42 - ;; - 70) - CHROME_DRIVER_VER=2.45 - ;; - 71) - CHROME_DRIVER_VER=2.46 - ;; - 72) - CHROME_DRIVER_VER=2.46 - ;; - 73) - CHROME_DRIVER_VER=73.0.3683.68 - ;; - 74) - CHROME_DRIVER_VER=74.0.3729.6 - ;; - 75) - CHROME_DRIVER_VER=75.0.3770.8 - ;; - 76) - CHROME_DRIVER_VER=76.0.3809.68 - ;; - 77) - CHROME_DRIVER_VER=77.0.3865.40 - ;; - 78) - CHROME_DRIVER_VER=78.0.3904.70 - ;; - 79) - CHROME_DRIVER_VER=79.0.3945.36 - ;; - 80) - CHROME_DRIVER_VER=80.0.3987.16 - ;; - 81) - CHROME_DRIVER_VER=81.0.4044.69 - ;; - 83) - CHROME_DRIVER_VER=83.0.4103.39 - ;; - 84) - CHROME_DRIVER_VER=84.0.4147.30 - ;; - 85) - CHROME_DRIVER_VER=85.0.4183.83 - ;; - 86) - CHROME_DRIVER_VER=86.0.4240.22 - ;; - *) - CHROME_DRIVER_VER=${DEFAULT_CHROME_DRIVER_VER} - ;; - esac - fi - echo "Chrome Driver Version: ${CHROME_DRIVER_VER}" -} - -function setStandaloneVersion() { - if [[ -z ${SE_STANDALONE_VER} ]]; - then - SE_STANDALONE_VER=${DEFAULT_STANDALONE_VER} - fi - echo "Selenium Standalone Version: ${SE_STANDALONE_VER}" -} - -function removeSymlinks() { - # remove symlinks if found - CHROME_DRIVER_LINK=${NODE_MODULES}/webdriver-manager/selenium/chromedriver - if [[ -f ${CHROME_DRIVER_LINK} ]]; - then - rm ${CHROME_DRIVER_LINK} - fi - SE_STANDALONE_LINK=${NODE_MODULES}/webdriver-manager/selenium/selenium-server-standalone.jar - if [[ -f ${SE_STANDALONE_LINK} ]]; - then - rm ${SE_STANDALONE_LINK} - fi -} - -function findLatestStandaloneVersion() { - SE_STANDALONE_LATEST=$(ls -t1 ${NODE_MODULES}/webdriver-manager/selenium/selenium-server-standalone-*.jar | head -1) - SE_STANDALONE_REAL_VER=$(echo ${SE_STANDALONE_LATEST} | sed -En 's/.*\/selenium-server-standalone-(.*).jar/\1/p') - echo "Real Standalone Version: ${SE_STANDALONE_REAL_VER}" -} - -function updateDrivers() { - # update the chromedriver and standalone driver - ${NODE_MODULES}/webdriver-manager/bin/webdriver-manager update --versions.chrome ${CHROME_DRIVER_VER} --gecko false --versions.standalone ${SE_STANDALONE_VER} - CHROME_DRIVER_FILE_NAME=chromedriver_${CHROME_DRIVER_VER} - if [[ ${SE_STANDALONE_VER} == 'latest' ]]; - then - findLatestStandaloneVersion - else - SE_STANDLONE_REAL_VER=${SE_STANDALONE_VER} - fi - SE_STANDALONE_FILE_NAME=selenium-server-standalone-${SE_STANDALONE_REAL_VER}.jar -} - -function createSymlinks() { - # (re-)create the symlinks - ln -s ${CHROME_DRIVER_FILE_NAME} ${CHROME_DRIVER_LINK} - ln -s ${SE_STANDALONE_FILE_NAME} ${SE_STANDALONE_LINK} -} - -setChromeDriverVersion -setStandaloneVersion -setTargetPath -removeSymlinks -updateDrivers -createSymlinks diff --git a/src/Security.js b/src/Security.js index 506fc9ab..2ad8ad0e 100644 --- a/src/Security.js +++ b/src/Security.js @@ -29,7 +29,7 @@ const Security = (props) => { setAuthState(authService.getAuthState()); }); - if (!authService._oktaAuth.token.isLoginRedirect()) { + if (!authService._oktaAuth.token.isLoginRedirect() && !authService._pending.handleAuthentication) { // Trigger an initial change event to make sure authState is latest when not in loginRedirect state authService.updateAuthState(); } diff --git a/test/e2e/harness/package.json b/test/e2e/harness/package.json index 112d6327..ed838dcd 100644 --- a/test/e2e/harness/package.json +++ b/test/e2e/harness/package.json @@ -34,7 +34,7 @@ "start": "PORT=8080 react-app-rewired start", "build": "react-app-rewired build", "kill:port": "kill -s TERM $(lsof -t -i:8080 -sTCP:LISTEN) || true", - "pretest": "../../../scripts/update_se_drivers.sh 0", + "pretest": "node ../../../scripts/update-se-drivers.js", "wait:server": "BROWSER=none yarn start & ./node_modules/.bin/wait-on http://localhost:8080", "test": "yarn wait:server && yarn protractor", "posttest": "yarn kill:port", diff --git a/test/jest/loginCallback.test.js b/test/jest/loginCallback.test.js index 3feb02d8..999ef8cb 100644 --- a/test/jest/loginCallback.test.js +++ b/test/jest/loginCallback.test.js @@ -16,6 +16,7 @@ describe('', () => { updateAuthState: jest.fn(), getAuthState: jest.fn().mockImplementation(() => authState), handleAuthentication: jest.fn(), + _pending: {}, _oktaAuth: { token: { isLoginRedirect: jest.fn().mockImplementation(() => false) diff --git a/test/jest/secureRoute.test.js b/test/jest/secureRoute.test.js index fd617a2c..d85e00c3 100644 --- a/test/jest/secureRoute.test.js +++ b/test/jest/secureRoute.test.js @@ -19,6 +19,7 @@ describe('', () => { updateAuthState: jest.fn(), getAuthState: jest.fn().mockImplementation(() => authState), login: jest.fn(), + _pending: {}, _oktaAuth: { token: { isLoginRedirect: jest.fn().mockImplementation(() => false) diff --git a/test/jest/security.test.js b/test/jest/security.test.js index fa8e5fbd..89ca1f93 100644 --- a/test/jest/security.test.js +++ b/test/jest/security.test.js @@ -21,6 +21,7 @@ describe('', () => { on: jest.fn(), updateAuthState: jest.fn(), getAuthState: jest.fn().mockImplementation(() => initialAuthState), + _pending: {}, _oktaAuth: { token: { isLoginRedirect: jest.fn().mockImplementation(() => false) diff --git a/yarn.lock b/yarn.lock index e7328ada..4401952b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3775,6 +3775,13 @@ axe-core@^3.5.4: resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-3.5.5.tgz#84315073b53fa3c0c51676c588d59da09a192227" integrity sha512-5P0QZ6J5xGikH780pghEdbEKijCTrruK9KxtPZCFWUpef0f6GipO+xEZ5GKCb020mmqgbiNO6TcA55CriL784Q== +axios@^0.21.0: + version "0.21.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.0.tgz#26df088803a2350dff2c27f96fef99fe49442aca" + integrity sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw== + dependencies: + follow-redirects "^1.10.0" + axobject-query@^2.0.2, axobject-query@^2.1.2: version "2.2.0" resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be" @@ -7903,7 +7910,7 @@ flush-write-stream@^1.0.0: inherits "^2.0.3" readable-stream "^2.3.6" -follow-redirects@^1.0.0: +follow-redirects@^1.0.0, follow-redirects@^1.10.0: version "1.13.0" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db" integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==