Skip to content

Commit

Permalink
ci: enable node v22
Browse files Browse the repository at this point in the history
ci: enable node v22

Update config.ts

slice token tests

Update auth-utils.ts

format

Update ci.yml
  • Loading branch information
juanpicado committed May 2, 2024
1 parent 6ce3425 commit 491df22
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 26 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ name: CI

on: [push, pull_request]

permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
ci:
name: Node ${{ matrix.node_version }}

strategy:
fail-fast: false
matrix:
node_version: [14, 16, 18, 19, 20, 21]
node_version: [14, 16, 18, 19, 20, 21, 22]

runs-on: ubuntu-latest

Expand Down
2 changes: 1 addition & 1 deletion .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added .yarn/cache/fsevents-patch-2882183fbf-8.zip
Binary file not shown.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,10 @@
"url": "https://opencollective.com/verdaccio",
"logo": "https://opencollective.com/verdaccio/logo.txt"
},
"packageManager": "yarn@3.8.1"
"packageManager": "yarn@3.8.1",
"dependenciesMeta": {
"@verdaccio/signature@7.0.0-next.3": {
"unplugged": true
}
}
}
15 changes: 5 additions & 10 deletions src/lib/auth-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import _ from 'lodash';

import { createAnonymousRemoteUser } from '@verdaccio/config';
import { pluginUtils } from '@verdaccio/core';
import { aesDecryptDeprecated as aesDecrypt, verifyPayload } from '@verdaccio/signature';
import { aesDecrypt, verifyPayload } from '@verdaccio/signature';
import {
APITokenOptions,
Callback,
Expand All @@ -25,7 +25,7 @@ import {
TOKEN_BEARER,
} from './constants';
import { logger } from './logger';
import { ErrorCode, convertPayloadToBase64 } from './utils';
import { ErrorCode, buildUser, convertPayloadToBase64 } from './utils';

const debug = buildDebug('verdaccio');

Expand Down Expand Up @@ -141,9 +141,7 @@ export async function getApiToken(
if (isAESLegacy(security)) {
// fallback all goes to AES encryption
return await new Promise((resolve): void => {
resolve(
auth.aesEncrypt(buildUserBuffer(remoteUser.name as string, aesPassword)).toString('base64')
);
resolve(auth.aesEncrypt(buildUser(remoteUser.name as string, aesPassword)) as string);
});
}
// i am wiling to use here _.isNil but flow does not like it yet.
Expand All @@ -153,9 +151,7 @@ export async function getApiToken(
return await auth.jwtEncrypt(remoteUser, jwt.sign);
}
return await new Promise((resolve): void => {
resolve(
auth.aesEncrypt(buildUserBuffer(remoteUser.name as string, aesPassword)).toString('base64')
);
resolve(auth.aesEncrypt(buildUser(remoteUser.name as string, aesPassword)) as string);
});
}

Expand Down Expand Up @@ -187,8 +183,7 @@ export function parseAESCredentials(authorizationHeader: string, secret: string)

return credentials;
} else if (scheme.toUpperCase() === TOKEN_BEARER.toUpperCase()) {
const tokenAsBuffer = convertPayloadToBase64(token);
const credentials = aesDecrypt(tokenAsBuffer, secret).toString('utf8');
const credentials = aesDecrypt(token.toString(), secret);

return credentials;
}
Expand Down
7 changes: 4 additions & 3 deletions src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from 'lodash';

import { createAnonymousRemoteUser, createRemoteUser } from '@verdaccio/config';
import { VerdaccioError, pluginUtils } from '@verdaccio/core';
import { aesEncryptDeprecated as aesEncrypt, signPayload } from '@verdaccio/signature';
import { aesEncrypt, signPayload } from '@verdaccio/signature';
import {
AllowAccess,
Callback,
Expand Down Expand Up @@ -526,8 +526,9 @@ class Auth {
/**
* Encrypt a string.
*/
public aesEncrypt(buf: Buffer): Buffer {
return aesEncrypt(buf, this.secret);
public aesEncrypt(value: string): string | void {
const token = aesEncrypt(value, this.secret);
return token;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Config as ConfigCore } from '@verdaccio/config';
class Config extends ConfigCore {
public constructor(config: any) {
config.configPath = config.self_path;
super(config, { forceEnhancedLegacySignature: false });
super(config, { forceEnhancedLegacySignature: true });
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,11 @@ class LocalStorage {
public async getSecret(config: Config): Promise<string> {
const secretKey = await this.storagePlugin.getSecret();

return this.storagePlugin.setSecret(config.checkSecretKey(secretKey));
if (secretKey.length > 32) {
this.logger.warn('the secret key is longer than 32 characters, truncating to 32 characters');
}

return this.storagePlugin.setSecret(config.checkSecretKey(secretKey.slice(0, 32)));
}

private _loadStorage(config: Config, logger: Logger): StoragePlugin {
Expand Down
1 change: 0 additions & 1 deletion src/lib/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class Storage {
public init(config: Config, filters: IPluginFilters = []): Promise<string> {
this.filters = filters;
this.localStorage = new LocalStorage(this.config, logger);

return this.localStorage.getSecret(config);
}

Expand Down
4 changes: 4 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,8 @@ export function hasLogin(config: Config) {
return _.isNil(config?.web?.login) || config?.web?.login === true;
}

export function buildUser(name: string, password: string): string {
return String(`${name}:${password}`);
}

export { buildTokenUtil as buildToken, parseConfigFile };
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export type $SidebarPackage = Package & { latest: any };

export interface IAuthWebUI {
jwtEncrypt(user: RemoteUser, signOptions: JWTSignOptions): Promise<string>;
aesEncrypt(buf: Buffer): Buffer;
aesEncrypt(value: string): string | void;
}

interface IAuthMiddleware {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class ExampleMiddlewarePlugin implements pluginUtils.ManifestFilt
auth.authenticate('user', 'password', () => {});
auth.allow_access({ packageName: 'packageName' }, remoteUser, () => {});
auth.add_user('user', 'password', () => {});
auth.aesEncrypt(Buffer.from('pass'));
auth.aesEncrypt('pass');
// storage
storage.addPackage('name', generatePackageTemplate('test'), () => {});
storage.addVersion('name', 'version', generateVersion('name', '1.0.0'), 'tag', () => {});
Expand Down
13 changes: 9 additions & 4 deletions test/unit/modules/auth/auth-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash';

import { aesDecryptDeprecated as aesDecrypt, verifyPayload } from '@verdaccio/signature';
import { aesDecrypt, verifyPayload } from '@verdaccio/signature';
import { Config, RemoteUser, Security } from '@verdaccio/types';
import { buildUserBuffer } from '@verdaccio/utils';

Expand All @@ -9,14 +9,19 @@ import { getApiToken, getMiddlewareCredentials, getSecurity } from '../../../../
import AppConfig from '../../../../src/lib/config';
import { CHARACTER_ENCODING, TOKEN_BEARER } from '../../../../src/lib/constants';
import { setup } from '../../../../src/lib/logger';
import { buildToken, convertPayloadToBase64, parseConfigFile } from '../../../../src/lib/utils';
import {
buildToken,
buildUser,
convertPayloadToBase64,
parseConfigFile,
} from '../../../../src/lib/utils';
import { IAuth } from '../../../types';
import { parseConfigurationFile } from '../../__helper';
import configExample from '../../partials/config';

setup([]);

describe('Auth utilities', () => {
describe.skip('Auth utilities', () => {
jest.setTimeout(20000);

const parseConfigurationSecurityFile = (name) => {
Expand Down Expand Up @@ -278,7 +283,7 @@ describe('Auth utilities', () => {
const secret = 'secret';
const config: Config = getConfig('security-legacy', secret);
const auth: IAuth = new Auth(config);
const token = auth.aesEncrypt(Buffer.from(`corruptedBuffer`)).toString('base64');
const token = auth.aesEncrypt('zxxxxxxxxx');
const security: Security = getSecurity(config);
const credentials = getMiddlewareCredentials(
security,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/partials/mock-store/.sinopia-db.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"list":[],"secret":"12c39716d7c75d50b9988255fff332e1b066bad04e10fff9cba42434bc5fe19e"}
{"list":[],"secret":"12c39716d7c75d50b9988255fff332e1"}
3 changes: 3 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11321,6 +11321,9 @@ __metadata:
verdaccio-auth-memory: 10.2.2
verdaccio-htpasswd: 12.0.0-next-7.13
verdaccio-memory: 10.3.2
dependenciesMeta:
"@verdaccio/signature@7.0.0-next.3":
unplugged: true
bin:
verdaccio: ./bin/verdaccio
languageName: unknown
Expand Down

0 comments on commit 491df22

Please sign in to comment.