diff --git a/npm_and_yarn/lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb b/npm_and_yarn/lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb index 43f11d386c..6161d906d3 100644 --- a/npm_and_yarn/lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb +++ b/npm_and_yarn/lib/dependabot/npm_and_yarn/file_updater/npmrc_builder.rb @@ -214,8 +214,11 @@ def dependency_urls sig { returns(String) } def complete_npmrc_from_credentials + # removes attribute timeout to allow for job update, + # having a timeout=xxxxx value is causing some jobs to fail initial_content = T.must(T.must(npmrc_file).content) - .gsub(/^.*\$\{.*\}.*/, "").strip + "\n" + .gsub(/^.*\$\{.*\}.*/, "").strip.gsub(/^timeout.*/, "").strip + "\n" + return initial_content unless yarn_lock || package_lock return initial_content unless global_registry diff --git a/npm_and_yarn/spec/dependabot/npm_and_yarn/file_updater/npmrc_builder_spec.rb b/npm_and_yarn/spec/dependabot/npm_and_yarn/file_updater/npmrc_builder_spec.rb index 5a179a82d1..b972ecd9b1 100644 --- a/npm_and_yarn/spec/dependabot/npm_and_yarn/file_updater/npmrc_builder_spec.rb +++ b/npm_and_yarn/spec/dependabot/npm_and_yarn/file_updater/npmrc_builder_spec.rb @@ -724,6 +724,57 @@ end end end + + context "when dealing with an npmrc file with timeout" do + let(:dependency_files) { project_dependency_files("npm6/npmrc_env_timeout") } + + it "populates the already existing npmrc" do + expect(npmrc_content) + .to eq("legacy-peer-deps=true\n" \ + "loglevel=verbose\n\n" \ + "fetch-retries=3\n" \ + "fetch-retry-maxtimeout=4\n" \ + "fetch-retry-mintimeout=3\n" \ + "fetch-timeout=400000\n\n" \ + "always-auth = true\n" \ + "strict-ssl = true\n" \ + "//npm.fury.io/dependabot/:_authToken=secret_token\n" \ + "registry = https://npm.fury.io/dependabot\n" \ + "//npm.fury.io/dependabot/:_authToken=my_token\n" \ + "always-auth = true\n") + end + + context "with basic auth credentials" do + let(:credentials) do + [Dependabot::Credential.new({ + "type" => "git_source", + "host" => "github.com", + "username" => "x-access-token", + "password" => "token" + }), Dependabot::Credential.new({ + "type" => "npm_registry", + "registry" => "npm.fury.io/dependabot", + "token" => "secret:token" + })] + end + + it "populates the already existing npmrc" do + expect(npmrc_content) + .to eq("legacy-peer-deps=true\n" \ + "loglevel=verbose\n\n" \ + "fetch-retries=3\n" \ + "fetch-retry-maxtimeout=4\n" \ + "fetch-retry-mintimeout=3\n" \ + "fetch-timeout=400000\n\n" \ + "always-auth = true\n" \ + "strict-ssl = true\n" \ + "//npm.fury.io/dependabot/:_authToken=secret_token\n" \ + "registry = https://npm.fury.io/dependabot\n" \ + "//npm.fury.io/dependabot/:_auth=c2VjcmV0OnRva2Vu\n" \ + "always-auth = true\n") + end + end + end end end diff --git a/npm_and_yarn/spec/fixtures/projects/npm6/npmrc_env_timeout/.npmrc b/npm_and_yarn/spec/fixtures/projects/npm6/npmrc_env_timeout/.npmrc new file mode 100644 index 0000000000..1a4c9252f1 --- /dev/null +++ b/npm_and_yarn/spec/fixtures/projects/npm6/npmrc_env_timeout/.npmrc @@ -0,0 +1,11 @@ +legacy-peer-deps=true +loglevel=verbose +timeout=90000 +fetch-retries=3 +fetch-retry-maxtimeout=4 +fetch-retry-mintimeout=3 +fetch-timeout=400000 +_auth = ${NPM_AUTH} +always-auth = true +strict-ssl = true +//npm.fury.io/dependabot/:_authToken=secret_token diff --git a/npm_and_yarn/spec/fixtures/projects/npm6/npmrc_env_timeout/package-lock.json b/npm_and_yarn/spec/fixtures/projects/npm6/npmrc_env_timeout/package-lock.json new file mode 100644 index 0000000000..517187dc86 --- /dev/null +++ b/npm_and_yarn/spec/fixtures/projects/npm6/npmrc_env_timeout/package-lock.json @@ -0,0 +1,76 @@ +{ + "name": "test", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "encoding": { + "version": "0.1.12", + "resolved": "https://npm.fury.io/dependabot/encoding/-/encoding-0.1.12.tgz", + "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", + "requires": { + "iconv-lite": "0.4.19" + } + }, + "es6-promise": { + "version": "3.3.1", + "resolved": "https://npm.fury.io/dependabot/es6-promise/-/es6-promise-3.3.1.tgz", + "integrity": "sha1-oIzd6EzNvzTQJ6FFG8kdS80ophM=" + }, + "etag": { + "version": "1.8.1", + "resolved": "https://npm.fury.io/dependabot/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=", + "dev": true + }, + "fetch-factory": { + "version": "0.0.1", + "resolved": "https://npm.fury.io/dependabot/fetch-factory/-/fetch-factory-0.0.1.tgz", + "integrity": "sha1-4AdgWb2zHjFHx1s7jAQTO6jH4HE=", + "requires": { + "es6-promise": "3.3.1", + "isomorphic-fetch": "2.2.1", + "lodash": "3.10.1" + } + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": false, + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "is-stream": { + "version": "1.1.0", + "resolved": "https://npm.fury.io/dependabot/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + }, + "isomorphic-fetch": { + "version": "2.2.1", + "resolved": "https://npm.fury.io/dependabot/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", + "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", + "requires": { + "node-fetch": "1.7.3", + "whatwg-fetch": "2.0.3" + } + }, + "lodash": { + "version": "3.10.1", + "resolved": "https://npm.fury.io/dependabot/lodash/-/lodash-3.10.1.tgz", + "integrity": "sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=" + }, + "node-fetch": { + "version": "1.7.3", + "resolved": "https://npm.fury.io/dependabot/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "requires": { + "encoding": "0.1.12", + "is-stream": "1.1.0" + } + }, + "whatwg-fetch": { + "version": "2.0.3", + "resolved": "https://npm.fury.io/dependabot/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", + "integrity": "sha1-nITsLc9oGH/wC8ZOEnS0QhduHIQ=" + } + } + } + \ No newline at end of file diff --git a/npm_and_yarn/spec/fixtures/projects/npm6/npmrc_env_timeout/package.json b/npm_and_yarn/spec/fixtures/projects/npm6/npmrc_env_timeout/package.json new file mode 100644 index 0000000000..9bf13f32a4 --- /dev/null +++ b/npm_and_yarn/spec/fixtures/projects/npm6/npmrc_env_timeout/package.json @@ -0,0 +1,25 @@ +{ + "name": "{{ name }}", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no\\ test\ specified\" && exit 1", + "prettify": "prettier --write \"{{packages/*/src,examples,cypress,scripts}/**/,}*.{js,jsx,ts,tsx,css,md}\"" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/waltfy/PROTO_TEST.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/waltfy/PROTO_TEST/issues" + }, + "homepage": "https://github.com/waltfy/PROTO_TEST#readme", + "dependencies": { + "fetch-factory": "^0.0.1" + }, + "devDependencies": { + "etag" : "^1.0.0" + }}