diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..c8f5df6 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,46 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/node:8.11 + + working_directory: ~/repo + + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "package.json" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: yarn install + + - save_cache: + paths: + - node_modules + key: v1-dependencies-{{ checksum "package.json" }} + + # test + - run: + name: "test" + command: yarn test + + # coverage + - run: + name: "coverage" + command: yarn coverage --ci --testResultsProcessor="jest-junit" + environment: + JEST_JUNIT_OUTPUT: "reports/junit/js-test-results.xml" + + - store_test_results: + path: reports/junit + - store_artifacts: + path: reports/junit + + # coveralls + - run: + name: "coveralls" + command: yarn coverage --coverageReporters=text-lcov | yarn coveralls diff --git a/.gitignore b/.gitignore index 1bd7226..95d0e1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules +coverage *.swp diff --git a/README.md b/README.md index 3f78322..eb0d9f0 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,14 @@ [`@sagi.io/gcp-jwt`](https://www.npmjs.com/package/@sagi.io/gcp-jwt) helps you generate `JWT` from `GCP`'s service accounts. It uses the Web Crypto API under the hood. - The package works with accordance to [Google's JWT Auth guide](https://developers.google.com/identity/protocols/OAuth2ServiceAccount#jwt-auth). + +[![CircleCI](https://circleci.com/gh/sagi/gcp-jwt.svg?style=svg)](https://circleci.com/gh/gcp-jwt) +[![Coverage Status](https://coveralls.io/repos/github/sagi/gcp-jwt/badge.svg?branch=master)](https://coveralls.io/github/sagi/gcp-jwt?branch=master) +[![MIT License](https://img.shields.io/npm/l/@sagi.io/gcp-jwt.svg?style=flat-square)](http://opensource.org/licenses/MIT) +[![version](https://img.shields.io/npm/v/@sagi.io/gcp-jwt.svg?style=flat-square)](http://npm.im/@sagi.io/gcp-jwt) + ## Installation ~~~ @@ -26,7 +31,7 @@ For `Firestore` the `aud` is `https://firestore.googleapis.com/google.firestore. ## Cloudflare Workers -Cloudflare Workers exposes the `crypto` global for the `Web Crypto API`. +Cloudflare Workers expose the `crypto` global for the `Web Crypto API`. ~~~js const jwt = require('@sagi.io/gcp-jwt') diff --git a/package.json b/package.json index d5a65ee..945a6b0 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,17 @@ "author": "Sagi Kedmi (https://sagi.io)", "license": "MIT", "private": false, + "scripts": { + "test": "yarn jest", + "coverage": "yarn jest --coverage" + }, "dependencies": { "base64url": "^3.0.1" }, "devDependencies": { + "coveralls": "^3.0.3", "jest": "^24.8.0", + "jest-junit": "^6.4.0", "node-webcrypto-ossl": "^1.0.44", "prettier": "^1.17.0" } diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index ba6c8d4..dc299a8 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`gcp-jwt getGCPJWT 1`] = `"eyJhbGciOiJSUzI1NiIsImtpZCI6IjY4OTVlZDUyN2U0Mjc4NjEyYzY4M2UzMWVlMjBjMTBlZmNlMTQ4NTEiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwczovL2JhYmEiLCJpc3MiOiJjZnctcmVzdC1hcGktdGVzdDJAYW5vbi1kdmxwLmlhbS5nc2VydmljZWFjY291bnQuY29tIiwic3ViIjoiY2Z3LXJlc3QtYXBpLXRlc3QyQGFub24tZHZscC5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsImlhdCI6MTUzMDUxODIwNywiZXhwIjoxNTMwNTIxODA3fQ.abNtsrMvgKlJAFOlI3o4AZpymprc8hZMSAPjvWfUKrq-2HTrUv1l1VKXRi1GwB3XURenIBDxpQUd997Uq6gJbnqtMpRk5gmNSm__xqTsqtTK8-f7vKTaqx90SoSFATaO2aacvbI3vAQNW_Kn9LWMsAeR7fIo09fiUn-5Y3sHS4BNy5Fz8M6mftDckj_ErmGhHoaD7Ki2DKGbAKAwd2zGkVEKAPD73tRBYJtPl_bjy-cFc1MHEFJ8ZxoCFens4SyCiw1ZLBMo2UFCftvMBKXHD2M9Iw7xCC_5qlWMbYFC6vixpb2xQE4ojxB3Z0rLRtsrb9UWpvkqIow8VN6FWbaXIw"`; +exports[`gcp-jwt getGCPJWT 1`] = `"eyJhbGciOiJSUzI1NiIsImtpZCI6IjY4OTVlZDUyN2U0Mjc4NjEyYzY4M2UzMWVlMjBjMTBlZmNlMTQ4NTEiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwczovL2JhYmEiLCJpc3MiOiJjZnctcmVzdC1hcGktdGVzdDJAYXhhbXBsZS1wcm9qZWN0LmlhbS5nc2VydmljZWFjY291bnQuY29tIiwic3ViIjoiY2Z3LXJlc3QtYXBpLXRlc3QyQGF4YW1wbGUtcHJvamVjdC5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsImlhdCI6MTUzMDUxODIwNywiZXhwIjoxNTMwNTIxODA3fQ.imaBlJI2H-CEnKLSSpOQuZ7EkOrCciV8ib5CyL0R4rqjBYsplyfXUw-Nf90ZxBxjcG1_OCdYJ0y7zX4X453tRqGdebKu8qx1-Lfya4f6wj4gxiUbJUoEy7-BURfR5LoSlcaYAOuJxzJyl1l7HnipPaCp-zS2ln9VuFWPCz3xjObsQHIKB14dk3GhAw2Nsk27D8-h27Iiygi3B8L-kB2aoUJZb93ve9qZPZ58lzngZBsQK3PXJX_wp8PLgyc1d5XUCmtlUEYRCrOGX94ABkuNZSFsfAIgsW3o1MU15e2_k5X_zeMzpJYD3K7bXu9EwHn3-ofedxuebiCobNBKnJ-WTw"`; diff --git a/yarn.lock b/yarn.lock index 13f037d..abb5563 100644 --- a/yarn.lock +++ b/yarn.lock @@ -439,6 +439,13 @@ are-we-there-yet@~1.1.2: delegates "^1.0.0" readable-stream "^2.0.6" +argparse@^1.0.7: + version "1.0.10" + resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" + integrity sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg== + dependencies: + sprintf-js "~1.0.2" + arr-diff@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520" @@ -775,6 +782,18 @@ core-util-is@1.0.2, core-util-is@~1.0.0: resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= +coveralls@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/coveralls/-/coveralls-3.0.3.tgz#83b1c64aea1c6afa69beaf50b55ac1bc4d13e2b8" + integrity sha512-viNfeGlda2zJr8Gj1zqXpDMRjw9uM54p7wzZdvLRyOgnAfCe974Dq4veZkjJdxQXbmdppu6flEajFYseHYaUhg== + dependencies: + growl "~> 1.10.0" + js-yaml "^3.11.0" + lcov-parse "^0.0.10" + log-driver "^1.2.7" + minimist "^1.2.0" + request "^2.86.0" + cross-spawn@^6.0.0: version "6.0.5" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" @@ -974,6 +993,11 @@ esprima@^3.1.3: resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633" integrity sha1-/cpRzuYTOJXjyI1TXOSdv/YqRjM= +esprima@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" + integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== + estraverse@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13" @@ -1226,6 +1250,11 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00" integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA== +"growl@~> 1.10.0": + version "1.10.5" + resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e" + integrity sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA== + growly@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" @@ -1756,6 +1785,16 @@ jest-jasmine2@^24.8.0: pretty-format "^24.8.0" throat "^4.0.0" +jest-junit@^6.4.0: + version "6.4.0" + resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-6.4.0.tgz#23e15c979fa6338afde46f2d2ac2a6b7e8cf0d9e" + integrity sha512-GXEZA5WBeUich94BARoEUccJumhCgCerg7mXDFLxWwI2P7wL3Z7sGWk+53x343YdBLjiMR9aD/gYMVKO+0pE4Q== + dependencies: + jest-validate "^24.0.0" + mkdirp "^0.5.1" + strip-ansi "^4.0.0" + xml "^1.0.1" + jest-leak-detector@^24.8.0: version "24.8.0" resolved "https://registry.yarnpkg.com/jest-leak-detector/-/jest-leak-detector-24.8.0.tgz#c0086384e1f650c2d8348095df769f29b48e6980" @@ -1919,7 +1958,7 @@ jest-util@^24.8.0: slash "^2.0.0" source-map "^0.6.0" -jest-validate@^24.8.0: +jest-validate@^24.0.0, jest-validate@^24.8.0: version "24.8.0" resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-24.8.0.tgz#624c41533e6dfe356ffadc6e2423a35c2d3b4849" integrity sha512-+/N7VOEMW1Vzsrk3UWBDYTExTPwf68tavEPKDnJzrC6UlHtUDU/fuEdXqFoHzv9XnQ+zW6X3qMZhJ3YexfeLDA== @@ -1965,6 +2004,14 @@ jest@^24.8.0: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== +js-yaml@^3.11.0: + version "3.13.1" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847" + integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw== + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + jsbn@~0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" @@ -2080,6 +2127,11 @@ lcid@^2.0.0: dependencies: invert-kv "^2.0.0" +lcov-parse@^0.0.10: + version "0.0.10" + resolved "https://registry.yarnpkg.com/lcov-parse/-/lcov-parse-0.0.10.tgz#1b0b8ff9ac9c7889250582b70b71315d9da6d9a3" + integrity sha1-GwuP+ayceIklBYK3C3ExXZ2m2aM= + left-pad@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e" @@ -2126,6 +2178,11 @@ lodash@^4.17.11: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg== +log-driver@^1.2.7: + version "1.2.7" + resolved "https://registry.yarnpkg.com/log-driver/-/log-driver-1.2.7.tgz#63b95021f0702fedfa2c9bb0a24e7797d71871d8" + integrity sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg== + loose-envify@^1.0.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" @@ -2821,7 +2878,7 @@ request-promise-native@^1.0.5: stealthy-require "^1.1.1" tough-cookie "^2.3.3" -request@^2.87.0: +request@^2.86.0, request@^2.87.0: version "2.88.0" resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef" integrity sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg== @@ -3109,6 +3166,11 @@ split-string@^3.0.1, split-string@^3.0.2: dependencies: extend-shallow "^3.0.0" +sprintf-js@~1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" + integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= + sshpk@^1.7.0: version "1.16.1" resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.16.1.tgz#fb661c0bef29b39db40769ee39fa70093d6f6877" @@ -3541,6 +3603,11 @@ xml-name-validator@^3.0.0: resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a" integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw== +xml@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5" + integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU= + "y18n@^3.2.1 || ^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b"