mirror of
https://github.com/logto-io/logto.git
synced 2024-12-23 20:33:16 -05:00
chore(connector): fix text encoding identifier cases (#1824)
* chore(connector): fix text encoding identifier cases * chore(connector): fix UT signing results due to the changes in parameters
This commit is contained in:
parent
d0e7d7a9dd
commit
dfa65938bf
7 changed files with 12 additions and 26 deletions
|
@ -1,5 +1,3 @@
|
|||
// FIXME: @Darcy
|
||||
/* eslint-disable unicorn/text-encoding-identifier-case */
|
||||
/**
|
||||
* The Implementation of OpenID Connect of Alipay Web Open Platform.
|
||||
* https://opendocs.alipay.com/open/218/105325
|
||||
|
@ -67,7 +65,7 @@ export const getAccessToken = async (code: string, config: AlipayNativeConfig) =
|
|||
version: '1.0',
|
||||
grant_type: 'authorization_code',
|
||||
code,
|
||||
charset: 'UTF8',
|
||||
charset: 'utf8',
|
||||
...config,
|
||||
};
|
||||
const signedSearchParameters = signingParameters(initSearchParameters);
|
||||
|
@ -120,7 +118,7 @@ const getUserInfo =
|
|||
grant_type: 'authorization_code',
|
||||
auth_token: accessToken,
|
||||
biz_content: JSON.stringify({}),
|
||||
charset: 'UTF8',
|
||||
charset: 'utf8',
|
||||
...config,
|
||||
};
|
||||
const signedSearchParameters = signingParameters(initSearchParameters);
|
||||
|
@ -191,4 +189,3 @@ const createAlipayNativeConnector: CreateConnector<SocialConnector> = async ({ g
|
|||
};
|
||||
|
||||
export default createAlipayNativeConnector;
|
||||
/* eslint-enable unicorn/text-encoding-identifier-case */
|
||||
|
|
|
@ -20,8 +20,6 @@ export const mockedAlipayNativePublicParameters = {
|
|||
grantType: 'authorization_code',
|
||||
timestamp: mockedTimestamp,
|
||||
version: '1.0',
|
||||
// FIXME: @Darcy
|
||||
// eslint-disable-next-line unicorn/text-encoding-identifier-case
|
||||
charset: 'UTF8',
|
||||
charset: 'utf8',
|
||||
method: '<method-placeholder>',
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@ describe('signingParameters', () => {
|
|||
it('should return exact signature with the given parameters (functionality check)', () => {
|
||||
const decamelizedParameters = signingParameters(testingParameters);
|
||||
expect(decamelizedParameters.sign).toBe(
|
||||
'td9+u0puul3HgbwLGL1X6z/vKKB/K25K5pjtLT/snQOp292RX3Y5j+FQUVuazTI2l65GpoSgA83LWNT9htQgtmdBmkCQ3bO6RWs38+2ZmBmH7MvpHx4ebUDhtebLUmHNuRFaNcpAZW92b0ZSuuJuahpLK8VNBgXljq+x0aD7WCRudPxc9fikR65NGxr5bwepl/9IqgMxwtajh1+PEJyhGGJhJxS1dCktGN0EiWXWNiogYT8NlFVCmw7epByKzCBWu4sPflU52gJMFHTdbav/0Tk/ZBs8RyP8Z8kcJA0jom2iT+dHqDpgkdzEmsR360UVNKCu5X7ltIiiObsAWmfluQ=='
|
||||
'jqVzRnwdvBEIocvKGZlZ4X3CK0pEsm8HpRWL9FtGS+P8ZRehh+Wvb3lmXWf0fhTIHmcZahQMAnLFO3OmqcwlUrs4PuRgPVmLG6mK087tkw/GP18hlstnD1hN3DS98eZZQsn8psxdHQ1qtzuik1fM0hiZvR7d/Pr72yNhIzgzWa66wBXJGYc6cmSQzB7g5hFg7L/SC55Xk205tkXkenPO9ti2TY8+bWOEZ4hAteWGftwCROz+1ne3EVrt2e/LpQQvRmDPhMIRVEShmcGTNj0ovnjN2K4Uo/YB7+hPLJkrGpYBV4hDEV91KQ9RybmE927xgIzXl7xbiHvK+BayFGNzFA=='
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -33,7 +33,7 @@ describe('signingParameters', () => {
|
|||
emptyProperty: '',
|
||||
});
|
||||
expect(decamelizedParameters.sign).toBe(
|
||||
'td9+u0puul3HgbwLGL1X6z/vKKB/K25K5pjtLT/snQOp292RX3Y5j+FQUVuazTI2l65GpoSgA83LWNT9htQgtmdBmkCQ3bO6RWs38+2ZmBmH7MvpHx4ebUDhtebLUmHNuRFaNcpAZW92b0ZSuuJuahpLK8VNBgXljq+x0aD7WCRudPxc9fikR65NGxr5bwepl/9IqgMxwtajh1+PEJyhGGJhJxS1dCktGN0EiWXWNiogYT8NlFVCmw7epByKzCBWu4sPflU52gJMFHTdbav/0Tk/ZBs8RyP8Z8kcJA0jom2iT+dHqDpgkdzEmsR360UVNKCu5X7ltIiiObsAWmfluQ=='
|
||||
'jqVzRnwdvBEIocvKGZlZ4X3CK0pEsm8HpRWL9FtGS+P8ZRehh+Wvb3lmXWf0fhTIHmcZahQMAnLFO3OmqcwlUrs4PuRgPVmLG6mK087tkw/GP18hlstnD1hN3DS98eZZQsn8psxdHQ1qtzuik1fM0hiZvR7d/Pr72yNhIzgzWa66wBXJGYc6cmSQzB7g5hFg7L/SC55Xk205tkXkenPO9ti2TY8+bWOEZ4hAteWGftwCROz+1ne3EVrt2e/LpQQvRmDPhMIRVEShmcGTNj0ovnjN2K4Uo/YB7+hPLJkrGpYBV4hDEV91KQ9RybmE927xgIzXl7xbiHvK+BayFGNzFA=='
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// FIXME: @Darcy
|
||||
/* eslint-disable unicorn/text-encoding-identifier-case */
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
import * as iconv from 'iconv-lite';
|
||||
|
@ -35,7 +33,7 @@ export const signingParameters: SigningParameters = (
|
|||
|
||||
if (value) {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
return `${key}=${iconv.encode(value, rest.charset ?? 'UTF8')}`;
|
||||
return `${key}=${iconv.encode(value, rest.charset ?? 'utf8')}`;
|
||||
}
|
||||
|
||||
return '';
|
||||
|
@ -51,4 +49,3 @@ export const signingParameters: SigningParameters = (
|
|||
|
||||
return { ...decamelizeParameters, sign };
|
||||
};
|
||||
/* eslint-enable unicorn/text-encoding-identifier-case */
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// FIXME: @Darcy
|
||||
/* eslint-disable unicorn/text-encoding-identifier-case */
|
||||
import { ConnectorType, ConnectorMetadata, ConnectorPlatform } from '@logto/connector-core';
|
||||
|
||||
export const authorizationEndpoint = 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm';
|
||||
|
@ -13,8 +11,8 @@ export const alipaySigningAlgorithmMapping = {
|
|||
RSA2: 'RSA-SHA256',
|
||||
} as const;
|
||||
export const alipaySigningAlgorithms = ['RSA', 'RSA2'] as const;
|
||||
export const charsetEnum = ['GBK', 'UTF8'] as const;
|
||||
export const fallbackCharset = 'UTF8';
|
||||
export const charsetEnum = ['GBK', 'utf8'] as const;
|
||||
export const fallbackCharset = 'utf8';
|
||||
|
||||
export const invalidAccessTokenCode = ['20001'];
|
||||
|
||||
|
@ -46,4 +44,3 @@ export const defaultMetadata: ConnectorMetadata = {
|
|||
export const defaultTimeout = 5000;
|
||||
|
||||
export const timestampFormat = 'YYYY-MM-DD HH:mm:ss';
|
||||
/* eslint-enable unicorn/text-encoding-identifier-case */
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// FIXME: @Darcy
|
||||
/* eslint-disable unicorn/text-encoding-identifier-case */
|
||||
import { AlipayConfig } from './types';
|
||||
|
||||
export const mockedTimestamp = '2022-02-22 22:22:22';
|
||||
|
@ -8,7 +6,7 @@ export const mockedAlipayConfig: AlipayConfig = {
|
|||
appId: '2021000000000000',
|
||||
signType: 'RSA2',
|
||||
privateKey: '<private-key>',
|
||||
charset: 'UTF8',
|
||||
charset: 'utf8',
|
||||
};
|
||||
|
||||
export const mockedAlipayConfigWithValidPrivateKey: AlipayConfig = {
|
||||
|
@ -16,7 +14,7 @@ export const mockedAlipayConfigWithValidPrivateKey: AlipayConfig = {
|
|||
signType: 'RSA2',
|
||||
privateKey:
|
||||
'-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC52SvnlRfzJJDR\nA1h4MX2JWV7Yt1j+1gvtQuLh0RYbE0AgRyz8CXFcJegO8gNyUQ05vrc1RMVzvNh8\njfjLpIX8an88KE4FyoG5P8NWrwPw5ZXOnzdvNxAV8QWOU+rT4WAdCsx4++mLlb5v\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Oz4fQ5i8JNDatOOmvhL5B9ZZh+pWUXsAsGZJEAxvJZAoGAMPHO\n5GYN1KQil6wz3EFMA3Fg4wYEDIFCcg7uvbfvwACtaJtxU18QmbCfOIPQoUndFzwa\nUJSohljrvPuTIh3PSpX618GTL45EIszd2/I1iXAfig3qo+DqLjX/OwKmMmWBfB8H\n4dwqRv+O1LsGkLNS2AdHsSWWnd1S5kBfQ3AnQfUCgYACM8ldXZv7uGt9uZBmxile\nB0Hg5w7F1v9VD/m9ko+INAISz8OVkD83pCEoyHwlr20JjiF+yzAakOuq6rBi+l/V\n1veSiTDUcZhciuq1G178dFYepJqisFBu7bAM+WBS4agTTtxdSLZkHeS4VX+H3DOc\ntri43NXw6QS7uQ5/+2TsEw==\n-----END PRIVATE KEY-----',
|
||||
charset: 'UTF8',
|
||||
charset: 'utf8',
|
||||
};
|
||||
|
||||
export const mockedAlipayPublicParameters = {
|
||||
|
@ -26,4 +24,3 @@ export const mockedAlipayPublicParameters = {
|
|||
version: '1.0',
|
||||
method: '<method-placeholder>',
|
||||
};
|
||||
/* eslint-enable unicorn/text-encoding-identifier-case */
|
||||
|
|
|
@ -20,7 +20,7 @@ describe('signingParameters', () => {
|
|||
it('should return exact signature with the given parameters (functionality check)', () => {
|
||||
const decamelizedParameters = signingParameters(testingParameters);
|
||||
expect(decamelizedParameters.sign).toBe(
|
||||
'td9+u0puul3HgbwLGL1X6z/vKKB/K25K5pjtLT/snQOp292RX3Y5j+FQUVuazTI2l65GpoSgA83LWNT9htQgtmdBmkCQ3bO6RWs38+2ZmBmH7MvpHx4ebUDhtebLUmHNuRFaNcpAZW92b0ZSuuJuahpLK8VNBgXljq+x0aD7WCRudPxc9fikR65NGxr5bwepl/9IqgMxwtajh1+PEJyhGGJhJxS1dCktGN0EiWXWNiogYT8NlFVCmw7epByKzCBWu4sPflU52gJMFHTdbav/0Tk/ZBs8RyP8Z8kcJA0jom2iT+dHqDpgkdzEmsR360UVNKCu5X7ltIiiObsAWmfluQ=='
|
||||
'jqVzRnwdvBEIocvKGZlZ4X3CK0pEsm8HpRWL9FtGS+P8ZRehh+Wvb3lmXWf0fhTIHmcZahQMAnLFO3OmqcwlUrs4PuRgPVmLG6mK087tkw/GP18hlstnD1hN3DS98eZZQsn8psxdHQ1qtzuik1fM0hiZvR7d/Pr72yNhIzgzWa66wBXJGYc6cmSQzB7g5hFg7L/SC55Xk205tkXkenPO9ti2TY8+bWOEZ4hAteWGftwCROz+1ne3EVrt2e/LpQQvRmDPhMIRVEShmcGTNj0ovnjN2K4Uo/YB7+hPLJkrGpYBV4hDEV91KQ9RybmE927xgIzXl7xbiHvK+BayFGNzFA=='
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -30,7 +30,7 @@ describe('signingParameters', () => {
|
|||
emptyProperty: '',
|
||||
});
|
||||
expect(decamelizedParameters.sign).toBe(
|
||||
'td9+u0puul3HgbwLGL1X6z/vKKB/K25K5pjtLT/snQOp292RX3Y5j+FQUVuazTI2l65GpoSgA83LWNT9htQgtmdBmkCQ3bO6RWs38+2ZmBmH7MvpHx4ebUDhtebLUmHNuRFaNcpAZW92b0ZSuuJuahpLK8VNBgXljq+x0aD7WCRudPxc9fikR65NGxr5bwepl/9IqgMxwtajh1+PEJyhGGJhJxS1dCktGN0EiWXWNiogYT8NlFVCmw7epByKzCBWu4sPflU52gJMFHTdbav/0Tk/ZBs8RyP8Z8kcJA0jom2iT+dHqDpgkdzEmsR360UVNKCu5X7ltIiiObsAWmfluQ=='
|
||||
'jqVzRnwdvBEIocvKGZlZ4X3CK0pEsm8HpRWL9FtGS+P8ZRehh+Wvb3lmXWf0fhTIHmcZahQMAnLFO3OmqcwlUrs4PuRgPVmLG6mK087tkw/GP18hlstnD1hN3DS98eZZQsn8psxdHQ1qtzuik1fM0hiZvR7d/Pr72yNhIzgzWa66wBXJGYc6cmSQzB7g5hFg7L/SC55Xk205tkXkenPO9ti2TY8+bWOEZ4hAteWGftwCROz+1ne3EVrt2e/LpQQvRmDPhMIRVEShmcGTNj0ovnjN2K4Uo/YB7+hPLJkrGpYBV4hDEV91KQ9RybmE927xgIzXl7xbiHvK+BayFGNzFA=='
|
||||
);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue