0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-10 22:22:45 -05:00

test: add mock social connector (#1710)

* chore(test): add mock social connector package

add mock social connector package

* fix(test): cr update

cr udpate
This commit is contained in:
simeng-li 2022-08-01 15:09:51 +08:00 committed by GitHub
parent ea27f7d69a
commit 054899fb90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 309 additions and 255 deletions

View file

@ -95,7 +95,7 @@ jobs:
INTEGRATION_TEST: true
NODE_ENV: production
DB_URL_DEFAULT: postgres://postgres:postgres@localhost:5432
ADDITIONAL_CONNECTOR_PACKAGES: '@logto/connector-mock-sms,@logto/connector-mock-email'
ADDITIONAL_CONNECTOR_PACKAGES: '@logto/connector-mock-sms,@logto/connector-mock-email,@logto/connector-mock-social'
- name: Sleep for 5 seconds
run: sleep 5

View file

@ -12,6 +12,7 @@ if [[ $INTEGRATION_TEST =~ ^(true|1)$ ]]; then
cd packages/core
pnpm link @logto/connector-mock-sms
pnpm link @logto/connector-mock-email
pnpm link @logto/connector-mock-social
cd -
NODE_ENV=production pnpm i --no-frozen-lockfile
else

View file

@ -0,0 +1,3 @@
# Social mock connector
For integration tests only.

View file

@ -0,0 +1,4 @@
{
"clientId": "<client-id>",
"clientSecret": "<client-secret>"
}

View file

@ -0,0 +1,6 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M20.64 12.2046C20.64 11.5664 20.5827 10.9527 20.4764 10.3636H12V13.845H16.8436C16.635 14.97 16.0009 15.9232 15.0477 16.5614V18.8196H17.9564C19.6582 17.2527 20.64 14.9455 20.64 12.2046Z" fill="#4285F4"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.9998 21C14.4298 21 16.467 20.1941 17.9561 18.8195L15.0475 16.5613C14.2416 17.1013 13.2107 17.4204 11.9998 17.4204C9.65567 17.4204 7.67158 15.8372 6.96385 13.71H3.95703V16.0418C5.43794 18.9831 8.48158 21 11.9998 21Z" fill="#34A853"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.96409 13.7099C6.78409 13.1699 6.68182 12.5931 6.68182 11.9999C6.68182 11.4068 6.78409 10.8299 6.96409 10.2899V7.95813H3.95727C3.34773 9.17313 3 10.5477 3 11.9999C3 13.4522 3.34773 14.8268 3.95727 16.0418L6.96409 13.7099Z" fill="#FBBC05"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.9998 6.57955C13.3211 6.57955 14.5075 7.03364 15.4402 7.92545L18.0216 5.34409C16.4629 3.89182 14.4257 3 11.9998 3C8.48158 3 5.43794 5.01682 3.95703 7.95818L6.96385 10.29C7.67158 8.16273 9.65567 6.57955 11.9998 6.57955Z" fill="#EA4335"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -0,0 +1,48 @@
{
"name": "@logto/connector-mock-social",
"version": "1.0.0-beta.2",
"description": "Social mock connector implementation.",
"main": "./lib/index.js",
"exports": "./lib/index.js",
"author": "Silverhand Inc. <contact@silverhand.io>",
"license": "MPL-2.0",
"private": true,
"files": [
"lib",
"docs",
"logo.svg",
"README.md"
],
"scripts": {
"precommit": "lint-staged",
"build": "rm -rf lib/ && tsc -p tsconfig.build.json",
"lint": "eslint --ext .ts src",
"lint:report": "pnpm lint --format json --output-file report.json",
"dev": "rm -rf lib/ && tsc-watch -p tsconfig.build.json --preserveWatchOutput --onSuccess \"node ./lib/index.js\"",
"prepack": "pnpm build"
},
"dependencies": {
"@logto/connector-types": "^1.0.0-beta.2",
"@logto/schemas": "^1.0.0-beta.2",
"@logto/shared": "^1.0.0-beta.1",
"@silverhand/essentials": "^1.1.0",
"zod": "^3.14.3"
},
"devDependencies": {
"@silverhand/eslint-config": "^0.17.0",
"@silverhand/ts-config": "^0.17.0",
"@types/node": "^16.3.1",
"eslint": "^8.19.0",
"lint-staged": "^13.0.0",
"prettier": "^2.3.2",
"tsc-watch": "^5.0.0",
"typescript": "^4.6.2"
},
"engines": {
"node": "^16.0.0"
},
"eslintConfig": {
"extends": "@silverhand"
},
"prettier": "@silverhand/eslint-config/.prettierrc"
}

View file

@ -0,0 +1,24 @@
import { ConnectorMetadata, ConnectorType, ConnectorPlatform } from '@logto/connector-types';
export const defaultMetadata: ConnectorMetadata = {
id: 'mock-social-connector',
target: 'mock-social',
type: ConnectorType.Social,
platform: ConnectorPlatform.Universal,
name: {
en: 'Mock Social',
'zh-CN': 'Mock 社交登录',
'ko-KR': 'Mock Social',
'tr-TR': 'Mock Social',
},
logo: './logo.svg',
logoDark: null,
description: {
en: 'Social mock connector description',
'zh-CN': 'Mock 社交登录连接器的描述',
'ko-KR': 'Social mock connector description',
'tr-TR': 'Social mock connector description',
},
readme: './README.md',
configTemplate: './docs/config-template.json',
};

View file

@ -0,0 +1,52 @@
import { randomUUID } from 'crypto';
import {
ConnectorError,
ConnectorErrorCodes,
GetAuthorizationUri,
GetUserInfo,
ConnectorMetadata,
Connector,
SocialConnectorInstance,
GetConnectorConfig,
} from '@logto/connector-types';
import { defaultMetadata } from './constant';
import { mockSocialConfigGuard, MockSocialConfig } from './types';
export default class MockSocialConnector implements SocialConnectorInstance<MockSocialConfig> {
public metadata: ConnectorMetadata = defaultMetadata;
private _connector?: Connector;
public get connector() {
if (!this._connector) {
throw new ConnectorError(ConnectorErrorCodes.General);
}
return this._connector;
}
public set connector(input: Connector) {
this._connector = input;
}
constructor(public readonly getConfig: GetConnectorConfig) {}
public validateConfig(config: unknown): asserts config is MockSocialConfig {
const result = mockSocialConfigGuard.safeParse(config);
if (!result.success) {
throw new ConnectorError(ConnectorErrorCodes.InvalidConfig, result.error);
}
}
public getAuthorizationUri: GetAuthorizationUri = async ({ state, redirectUri }) => {
return `http://mock.social.com/?state=${state}&redirect_uri=${redirectUri}`;
};
public getAccessToken = async () => randomUUID();
public getUserInfo: GetUserInfo = async () => ({
id: `mock-social-sub-${randomUUID()}`,
});
}

View file

@ -0,0 +1,29 @@
import { z } from 'zod';
export const mockSocialConfigGuard = z.object({
clientId: z.string(),
clientSecret: z.string(),
});
export type MockSocialConfig = z.infer<typeof mockSocialConfigGuard>;
export const accessTokenResponseGuard = z.object({
access_token: z.string(),
scope: z.string(),
token_type: z.string(),
});
export type AccessTokenResponse = z.infer<typeof accessTokenResponseGuard>;
export const userInfoResponseGuard = z.object({
sub: z.string(),
name: z.string().optional(),
given_name: z.string().optional(),
family_name: z.string().optional(),
picture: z.string().optional(),
email: z.string().optional(),
email_verified: z.boolean().optional(),
locale: z.string().optional(),
});
export type UserInfoResponse = z.infer<typeof userInfoResponseGuard>;

View file

@ -0,0 +1,10 @@
{
"extends": "@silverhand/ts-config/tsconfig.base",
"compilerOptions": {
"outDir": "lib",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}

View file

@ -0,0 +1,4 @@
{
"extends": "./tsconfig.base",
"include": ["src"]
}

View file

@ -0,0 +1,7 @@
{
"extends": "./tsconfig.base",
"compilerOptions": {
"types": ["node"]
},
"include": ["src"]
}

374
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff