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
9 changes: 0 additions & 9 deletions src/main/java/jenkins/plugins/nodejs/NodeJSConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ private NodeJSConstants() {
*/
public static final String NPM_USERCONFIG = "npm_config_userconfig";

/**
* Force npm to always require authentication when accessing the registry,
* even for GET requests.
* <p>
* Default: false<br>
* Type: Boolean
* </p>
*/
public static final String NPM_SETTINGS_ALWAYS_AUTH = "always-auth";
/**
* The base URL of the npm package registry.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package jenkins.plugins.nodejs.configfiles;

import static jenkins.plugins.nodejs.NodeJSConstants.NPM_SETTINGS_ALWAYS_AUTH;
import static jenkins.plugins.nodejs.NodeJSConstants.NPM_SETTINGS_AUTH;
import static jenkins.plugins.nodejs.NodeJSConstants.NPM_SETTINGS_AUTHTOKEN;
import static jenkins.plugins.nodejs.NodeJSConstants.NPM_SETTINGS_PASSWORD;
Expand Down Expand Up @@ -143,8 +142,6 @@ public String fillRegistry(String npmrcContent, Map<String, StandardCredentials>
// add scoped values to the user config file
npmrc.set(compose('@' + scope, NPM_SETTINGS_REGISTRY), registryURL);
if (credentials != null) { // NOSONAR
npmrc.set(compose(registryPrefix, NPM_SETTINGS_ALWAYS_AUTH), credentials != null);

// the _auth directive seems not be considered for scoped registry
// only authToken or username/password works
if (credentials instanceof UsernamePasswordCredentials) {
Expand All @@ -165,7 +162,6 @@ public String fillRegistry(String npmrcContent, Map<String, StandardCredentials>
// add values to the user config file
npmrc.set(NPM_SETTINGS_REGISTRY, registry.getUrl());
if (credentials != null) {
npmrc.set(compose(registryPrefix, NPM_SETTINGS_ALWAYS_AUTH), credentials != null);
if (credentials instanceof UsernamePasswordCredentials) {
UsernamePasswordCredentials usernamePassowrd = (UsernamePasswordCredentials) credentials;
String authValue = usernamePassowrd.getUsername() + ':' + Secret.toString(usernamePassowrd.getPassword());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package jenkins.plugins.nodejs.configfiles;

import static jenkins.plugins.nodejs.NodeJSConstants.NPM_SETTINGS_ALWAYS_AUTH;
import static jenkins.plugins.nodejs.NodeJSConstants.NPM_SETTINGS_AUTH;
import static jenkins.plugins.nodejs.NodeJSConstants.NPM_SETTINGS_PASSWORD;
import static jenkins.plugins.nodejs.NodeJSConstants.NPM_SETTINGS_REGISTRY;
Expand Down Expand Up @@ -116,18 +115,13 @@ private void verifyScopedRegistry(RegistryHelper helper, Npmrc npmrc, NPMRegistr
String registryPrefix = helper.calculatePrefix(registry.getUrl());

// scoped registry not depends on npm format, has always the registry prefix
String alwaysAuthKey = helper.compose(registryPrefix, NPM_SETTINGS_ALWAYS_AUTH);
String usernameKey = helper.compose(registryPrefix, NPM_SETTINGS_USER);
String passwordKey = helper.compose(registryPrefix, NPM_SETTINGS_PASSWORD);

for (String scope : registry.getScopesAsList()) {
assertThat(npmrc.contains(helper.compose(registryPrefix, NPM_SETTINGS_AUTH))).as("Unexpected value for " + NPM_SETTINGS_AUTH).isFalse();

if (registry.getCredentialsId() != null) {
// test require authentication, by default is false
assertThat(npmrc.contains(alwaysAuthKey)).as("key %s not found", NPM_SETTINGS_ALWAYS_AUTH).isTrue();
assertThat(npmrc.getAsBoolean(alwaysAuthKey)).isTrue();

// test credentials fields
assertThat(npmrc.get(usernameKey)).isEqualTo(user.getUsername());
String password = npmrc.get(passwordKey);
Expand All @@ -146,12 +140,8 @@ private void verifyScopedRegistry(RegistryHelper helper, Npmrc npmrc, NPMRegistr

private void verifyGlobalRegistry(RegistryHelper helper, NPMRegistry registry, Npmrc npmrc, boolean npm9Format) {
String registryPrefix = helper.calculatePrefix(registry.getUrl());
String alwaysAuthKey = npm9Format ? helper.compose(registryPrefix, NPM_SETTINGS_ALWAYS_AUTH) : NPM_SETTINGS_ALWAYS_AUTH;
String authKey = npm9Format ? helper.compose(registryPrefix, NPM_SETTINGS_AUTH) : NPM_SETTINGS_AUTH;

assertThat(npmrc.contains(alwaysAuthKey)).as("Unexpected value for %s", alwaysAuthKey).isEqualTo(registry.getCredentialsId() != null) //
;

if (registry.getCredentialsId() != null) {
// test _auth
String auth = npmrc.get(authKey);
Expand Down