fix: lint fix

This commit is contained in:
ryanycw
2023-08-28 11:20:53 +08:00
parent 4025d69c3f
commit b1a699068c
11 changed files with 445 additions and 102 deletions

View File

@@ -9,6 +9,7 @@ A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'

View File

@@ -1,2 +1,3 @@
# Opening an Issue
When initiating an issue, select a starting template: either Bug Report or Feature Improvement. If you're reporting a bug, ensure that you can demonstrate the bug through testing or a proof of concept. For suggesting a feature enhancement, name it with a clear problem description and verify that a similar request isn't already underway or completed. Be aware that not every issue might be considered necessary to fix, so be prepared to engage in discussions, answering any queries or comments others might have about the issue.

View File

@@ -1,16 +1,19 @@
# Local Development
# Troubleshooting Tips
* pull latest changes from master and `yarn install` and `yarn build`
* install circom if you haven't already
* run following command and set up Twitter API Key. By default, it's a invalid API key.
- pull latest changes from master and `yarn install` and `yarn build`
- install circom if you haven't already
- run following command and set up Twitter API Key. By default, it's a invalid API key.
```shell
cp packages/relay/.env_example packages/relay/.env
```
* you may start all daemons in one terminal window with `yarn start`, or start each daemon in a separate terminal window. If you start separately, it's easier to debug, since you don't need to restart hardhat node and redeploy contracts every time you change the code.
- you may start all daemons in one terminal window with `yarn start`, or start each daemon in a separate terminal window. If you start separately, it's easier to debug, since you don't need to restart hardhat node and redeploy contracts every time you change the code.
## Use VSCode Debugger to Debug Relay
With this configuration `.vscode/launch.json` in place, you can use VSCode debugger to debug relay.
```json
"version": "0.2.0",
"configurations": [
@@ -33,23 +36,30 @@ attach to process
![Set breakpoint](./images/SetBreakpoint.png)
and set breakpoint.
You may also use auto attach mode, which will automatically attach to the process when you start the relay server or run testing suite. If auto
You may also use auto attach mode, which will automatically attach to the process when you start the relay server or run testing suite. If auto
# Testing
In the root directory, run:
```shell
yarn run test
```
or run tests for a specific package:
```shell
yarn run test --scope @unirep-app/relay
```
To run specific test file:
```shell
yarn test test/login.test.ts
```
We use nock to mock the HTTP requests. If you want to run the tests with real HTTP requests. You can turn on nock debug mode by setting `DEBUG=nock.*` in front of your shell command and run the tests.
```shell
DEBUG=nock.* yarn test test/login.test.ts
```

View File

@@ -1,3 +1,4 @@
# Privacy Disclosure
// TODO: add more description and let user know
We modified Unirep contract to store hashed twitter user ID (handle) in Social TW project. Given any twitter user ID and known hash function, other people are able to know if a certain person has signed up for the Unirep system. However, they are not able to know one's interaction within Social TW.

View File

@@ -1,17 +1,20 @@
# System Overview
# Overview Diagram
[login flow](https://drive.google.com/file/d/1gP4fVwX9vjOVqCKJ2XYUMBYEn0ngH0cG/view?usp=sharing)
## UserService Status Code
We modified Unirep contract to store hashedUser ID in Social TW project
We modified Unirep contract to store hashedUser ID in Social TW project
The purpose
1. loginStatus = INIT: User has been initialize, then process sign up
2. loginStatus = REGISTERED: User has been signUp with own wallet
3. loginStatus = REGISTERED_SERVER: User has been signUp with server wallet. In this case, signMsg will be included
NOTINIT 0
after login to twitter
NOTINIT to INIT in `/api/user`
INIT in Unirep contract
after login to twitter
NOTINIT to INIT in `/api/user`
INIT in Unirep contract
INIT 1

View File

@@ -1 +1,317 @@
[{"inputs":[{"internalType":"contract Unirep","name":"_unirep","type":"address"},{"internalType":"contract EpochKeyVerifierHelper","name":"_epkHelper","type":"address"},{"internalType":"contract IVerifier","name":"_dataVerifier","type":"address"},{"internalType":"uint48","name":"_epochLength","type":"uint48"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint160","name":"attesterId","type":"uint160"}],"name":"AttesterIdNotMatch","type":"error"},{"inputs":[{"internalType":"uint256","name":"hashUserId","type":"uint256"},{"internalType":"enum UnirepApp.RegisterStatus","name":"status","type":"uint8"}],"name":"UserAlreadySignedUp","type":"error"},{"inputs":[{"internalType":"uint256","name":"hashUserId","type":"uint256"}],"name":"UserInitExpiry","type":"error"},{"inputs":[{"internalType":"uint256","name":"hashUserId","type":"uint256"}],"name":"UserInitStatusInvalid","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"epochKey","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"postId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":false,"internalType":"string","name":"content","type":"string"}],"name":"Post","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"hashUserId","type":"uint256"}],"name":"UserInitSuccess","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"hashUserId","type":"uint256"}],"name":"UserSignUpSuccess","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"epochKeyPostIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"epochKeyPostVoteMap","outputs":[{"internalType":"uint256","name":"upVote","type":"uint256"},{"internalType":"uint256","name":"downVote","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"hashUserId","type":"uint256"}],"name":"initUserStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"publicSignals","type":"uint256[]"},{"internalType":"uint256[8]","name":"proof","type":"uint256[8]"},{"internalType":"string","name":"content","type":"string"}],"name":"post","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"proofNullifier","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"hashUserId","type":"uint256"}],"name":"queryUserStatus","outputs":[{"internalType":"enum UnirepApp.RegisterStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"epochKey","type":"uint256"},{"internalType":"uint48","name":"targetEpoch","type":"uint48"},{"internalType":"uint256","name":"fieldIndex","type":"uint256"},{"internalType":"uint256","name":"val","type":"uint256"}],"name":"submitAttestation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"epochKey","type":"uint256"},{"internalType":"uint48","name":"targetEpoch","type":"uint48"},{"internalType":"uint256[]","name":"fieldIndices","type":"uint256[]"},{"internalType":"uint256[]","name":"vals","type":"uint256[]"}],"name":"submitManyAttestations","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unirep","outputs":[{"internalType":"contract Unirep","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"publicSignals","type":"uint256[]"},{"internalType":"uint256[8]","name":"proof","type":"uint256[8]"},{"internalType":"uint256","name":"hashUserId","type":"uint256"},{"internalType":"bool","name":"fromServer","type":"bool"}],"name":"userSignUp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[5]","name":"publicSignals","type":"uint256[5]"},{"internalType":"uint256[8]","name":"proof","type":"uint256[8]"}],"name":"verifyDataProof","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]
[
{
"inputs": [
{
"internalType": "contract Unirep",
"name": "_unirep",
"type": "address"
},
{
"internalType": "contract EpochKeyVerifierHelper",
"name": "_epkHelper",
"type": "address"
},
{
"internalType": "contract IVerifier",
"name": "_dataVerifier",
"type": "address"
},
{
"internalType": "uint48",
"name": "_epochLength",
"type": "uint48"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "uint160",
"name": "attesterId",
"type": "uint160"
}
],
"name": "AttesterIdNotMatch",
"type": "error"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "hashUserId",
"type": "uint256"
},
{
"internalType": "enum UnirepApp.RegisterStatus",
"name": "status",
"type": "uint8"
}
],
"name": "UserAlreadySignedUp",
"type": "error"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "hashUserId",
"type": "uint256"
}
],
"name": "UserInitExpiry",
"type": "error"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "hashUserId",
"type": "uint256"
}
],
"name": "UserInitStatusInvalid",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint256",
"name": "epochKey",
"type": "uint256"
},
{
"indexed": true,
"internalType": "uint256",
"name": "postId",
"type": "uint256"
},
{
"indexed": true,
"internalType": "uint256",
"name": "epoch",
"type": "uint256"
},
{
"indexed": false,
"internalType": "string",
"name": "content",
"type": "string"
}
],
"name": "Post",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "hashUserId",
"type": "uint256"
}
],
"name": "UserInitSuccess",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "hashUserId",
"type": "uint256"
}
],
"name": "UserSignUpSuccess",
"type": "event"
},
{
"inputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"name": "epochKeyPostIndex",
"outputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "", "type": "uint256" },
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"name": "epochKeyPostVoteMap",
"outputs": [
{ "internalType": "uint256", "name": "upVote", "type": "uint256" },
{ "internalType": "uint256", "name": "downVote", "type": "uint256" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "hashUserId",
"type": "uint256"
}
],
"name": "initUserStatus",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256[]",
"name": "publicSignals",
"type": "uint256[]"
},
{
"internalType": "uint256[8]",
"name": "proof",
"type": "uint256[8]"
},
{ "internalType": "string", "name": "content", "type": "string" }
],
"name": "post",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes32", "name": "", "type": "bytes32" }
],
"name": "proofNullifier",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "hashUserId",
"type": "uint256"
}
],
"name": "queryUserStatus",
"outputs": [
{
"internalType": "enum UnirepApp.RegisterStatus",
"name": "",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "epochKey",
"type": "uint256"
},
{
"internalType": "uint48",
"name": "targetEpoch",
"type": "uint48"
},
{
"internalType": "uint256",
"name": "fieldIndex",
"type": "uint256"
},
{ "internalType": "uint256", "name": "val", "type": "uint256" }
],
"name": "submitAttestation",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "epochKey",
"type": "uint256"
},
{
"internalType": "uint48",
"name": "targetEpoch",
"type": "uint48"
},
{
"internalType": "uint256[]",
"name": "fieldIndices",
"type": "uint256[]"
},
{ "internalType": "uint256[]", "name": "vals", "type": "uint256[]" }
],
"name": "submitManyAttestations",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "unirep",
"outputs": [
{ "internalType": "contract Unirep", "name": "", "type": "address" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256[]",
"name": "publicSignals",
"type": "uint256[]"
},
{
"internalType": "uint256[8]",
"name": "proof",
"type": "uint256[8]"
},
{
"internalType": "uint256",
"name": "hashUserId",
"type": "uint256"
},
{ "internalType": "bool", "name": "fromServer", "type": "bool" }
],
"name": "userSignUp",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256[5]",
"name": "publicSignals",
"type": "uint256[5]"
},
{
"internalType": "uint256[8]",
"name": "proof",
"type": "uint256[8]"
}
],
"name": "verifyDataProof",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
}
]

View File

@@ -32,6 +32,10 @@ export const TWITTER_ACCESS_TOKEN_URL =
export const TWITTER_USER_URL =
process.env.TWITTER_USER_URL ?? 'https://api.twitter.com/2/users/me'
const isInTest = typeof global.it === 'function';
export const TWITTER_CLIENT_ID = isInTest ? "test-client-id" : process.env.TWITTER_CLIENT_ID
export const TWITTER_CLIENT_KEY = isInTest ? "test-client-key" : process.env.TWITTER_CLIENT_KEY
const isInTest = typeof global.it === 'function'
export const TWITTER_CLIENT_ID = isInTest
? 'test-client-id'
: process.env.TWITTER_CLIENT_ID
export const TWITTER_CLIENT_KEY = isInTest
? 'test-client-key'
: process.env.TWITTER_CLIENT_KEY

View File

@@ -46,7 +46,9 @@ export default (
error instanceof Error &&
error.message.includes('The user has already signed up.')
) {
res.status(400).json({ error: 'The user has already signed up.' })
res.status(400).json({
error: 'The user has already signed up.',
})
} else {
res.status(500).json({ error: 'Internal server error' })
}

View File

@@ -19,26 +19,26 @@ export class UserService {
* - loginStatus = REGISTERED_SERVER: User has been signUp with server wallet
* In this case, signMsg will be included
*
* @param state from twitter api callback
* @param state from twitter api callback
* @param code from twitter api callback
*/
async loginOrInitUser(state: string, code: string): Promise<User> {
if (state != STATE) throw Error('wrong callback value')
try {
var userInfo = await TwitterClient.authClient.requestAccessToken(code as string)
var userInfo = await TwitterClient.authClient
.requestAccessToken(code as string)
.then((_) => TwitterClient.client.users.findMyUser())
} catch (error) {
console.log('error in getting user id', error)
throw Error('Error in login')
}
const userId = userInfo.data?.id!!
return await this.getLoginOrInitUser(userId)
}
async getLoginOrInitUser(userId: string) {
const hash = crypto.createHash('sha3-224')
const hashUserId = `0x${hash.update(userId).digest('hex')}`
const appContract = TransactionManager.appContract!!

View File

@@ -1,6 +1,6 @@
const epochLength = 300;
const PORT = parseInt(process.env.PORT ?? '8000', 10);
const HTTP_SERVER = `http://127.0.0.1:${PORT}`;
const epochLength = 300
const PORT = parseInt(process.env.PORT ?? '8000', 10)
const HTTP_SERVER = `http://127.0.0.1:${PORT}`
const CLIENT_URL = process.env.CLIENT_URL ?? 'http://localhost:3000'
export { PORT, HTTP_SERVER, epochLength, CLIENT_URL };
export { PORT, HTTP_SERVER, epochLength, CLIENT_URL }

View File

@@ -6,10 +6,7 @@ import * as chaiAsPromise from 'chai-as-promised'
import nock from 'nock'
import { deployContracts, startServer } from './environment'
import { userService } from '../src/services/UserService'
import {
TWITTER_CLIENT_ID,
TWITTER_CLIENT_KEY,
} from '../src/config'
import { TWITTER_CLIENT_ID, TWITTER_CLIENT_KEY } from '../src/config'
import { UserRegisterStatus } from '../src/enums/userRegisterStatus'
import { HTTP_SERVER, CLIENT_URL } from './configs'
import { ethers } from 'hardhat'
@@ -32,29 +29,26 @@ describe('LOGIN /login', () => {
let snapshot: any
let userState: UserState
let app, unirep
let db, prover, provider, TransactionManager, synchronizer;
let server: Server;
let db, prover, provider, TransactionManager, synchronizer
let server: Server
let hashMockUserId: string
let hashMockUserId2: string
before(async () => {
snapshot = await ethers.provider.send('evm_snapshot', [])
// open promise testing
chai.use(chaiAsPromise.default);
chai.use(chaiAsPromise.default)
// deploy contracts
({ unirep, app } = await deployContracts());
;({ unirep, app } = await deployContracts())
// start server
({ db, prover, provider, TransactionManager, synchronizer, server } = await startServer(
unirep,
app
));
;({ db, prover, provider, TransactionManager, synchronizer, server } =
await startServer(unirep, app))
const hash = crypto.createHash('sha3-224')
hashMockUserId = `0x${hash.update(mockUserId).digest('hex')}`;
hashMockUserId = `0x${hash.update(mockUserId).digest('hex')}`
const hash2 = crypto.createHash('sha3-224')
hashMockUserId2 = `0x${hash2.update(mockUserId2).digest('hex')}`;
hashMockUserId2 = `0x${hash2.update(mockUserId2).digest('hex')}`
})
after(async () => {
@@ -63,59 +57,61 @@ describe('LOGIN /login', () => {
})
it('/api/login, return url', async () => {
await chai.request(`${HTTP_SERVER}`)
await chai
.request(`${HTTP_SERVER}`)
.get('/api/login')
.then(res => {
expect(res.body.url).to.be.not.null;
expect(res).to.have.status(200);
.then((res) => {
expect(res.body.url).to.be.not.null
expect(res).to.have.status(200)
})
})
it('/api/user, init user with wrong code and return error', async () => {
// Suppress console.error and restore original console.error
const originalConsoleError = console.error;
console.log = console.error = console.warn = () => { };
const originalConsoleError = console.error
console.log = console.error = console.warn = () => {}
// mock with wrong code response
nock(TWITTER_API, { "encodedQueryParams": true })
nock(TWITTER_API, { encodedQueryParams: true })
.post('/2/oauth2/token')
.query({
code: wrongCode,
grant_type: "authorization_code",
grant_type: 'authorization_code',
client_id: TWITTER_CLIENT_ID,
redirect_uri: /^.*$/
redirect_uri: /^.*$/,
})
.matchHeader('content-type', 'application/x-www-form-urlencoded')
.matchHeader('authorization', `Basic ${token}`)
.reply(400, {
"error": "invalid_request",
"error_description": "Value passed for the authorization code was invalid."
});
error: 'invalid_request',
error_description:
'Value passed for the authorization code was invalid.',
})
nock(`${CLIENT_URL}`)
.get('/')
.query({
error: "apiError",
error: 'apiError',
})
.reply(200);
.reply(200)
await chai.request(`${HTTP_SERVER}`)
await chai
.request(`${HTTP_SERVER}`)
.get('/api/user')
.set('content-type', 'application/json')
.query({
state: mockState,
code: wrongCode,
})
.then(res => {
expect(res).to.have.status(200);
.then((res) => {
expect(res).to.have.status(200)
})
console.error = originalConsoleError;
console.error = originalConsoleError
})
it('/api/user, init user', async () => {
prepareUserLoginTwitterApiMock(mockUserId, mockCode, "access-token")
prepareUserLoginTwitterApiMock(mockUserId, mockCode, 'access-token')
nock(`${CLIENT_URL}`)
.get('/login')
@@ -123,17 +119,18 @@ describe('LOGIN /login', () => {
code: hashMockUserId,
status: `${UserRegisterStatus.INIT}`,
})
.reply(200);
.reply(200)
await chai.request(`${HTTP_SERVER}`)
await chai
.request(`${HTTP_SERVER}`)
.get('/api/user')
.set('content-type', 'application/json')
.query({
state: mockState,
code: mockCode,
})
.then(res => {
expect(res).to.have.status(200);
.then((res) => {
expect(res).to.have.status(200)
})
})
@@ -141,15 +138,16 @@ describe('LOGIN /login', () => {
const wallet = TransactionManager.wallet!!
const expectedSignMsg = await wallet.signMessage(hashMockUserId)
await chai.request(`${HTTP_SERVER}`)
await chai
.request(`${HTTP_SERVER}`)
.post('/api/identity')
.set('content-type', 'application/json')
.send({
hashUserId: hashMockUserId
hashUserId: hashMockUserId,
})
.then(res => {
expect(res.body.signMsg).to.equal(expectedSignMsg);
expect(res).to.have.status(200);
.then((res) => {
expect(res.body.signMsg).to.equal(expectedSignMsg)
expect(res).to.have.status(200)
})
})
@@ -182,8 +180,8 @@ describe('LOGIN /login', () => {
fromServer: false,
})
.then((res) => {
expect(res.body.status).to.equal('success');
expect(res.body.hash).to.be.not.null;
expect(res.body.status).to.equal('success')
expect(res.body.hash).to.be.not.null
expect(res).to.have.status(200)
})
})
@@ -224,8 +222,8 @@ describe('LOGIN /login', () => {
fromServer: true,
})
.then((res) => {
expect(res.body.status).to.equal('success');
expect(res.body.hash).to.be.not.null;
expect(res.body.status).to.equal('success')
expect(res.body.hash).to.be.not.null
expect(res).to.have.status(200)
})
})
@@ -249,7 +247,9 @@ describe('LOGIN /login', () => {
await userState.waitForSync()
let wrongSignupProof = await userState.genUserSignUpProof()
let publicSignals = wrongSignupProof.publicSignals.map((n) => n.toString())
let publicSignals = wrongSignupProof.publicSignals.map((n) =>
n.toString()
)
wrongSignupProof.identityCommitment = BigInt(0)
await chai
@@ -301,29 +301,30 @@ describe('LOGIN /login', () => {
})
it('/api/login, registered user with own wallet', async () => {
prepareUserLoginTwitterApiMock(mockUserId, mockCode, "access-token")
prepareUserLoginTwitterApiMock(mockUserId, mockCode, 'access-token')
nock(`${CLIENT_URL}`)
.get('/login')
.query({
code: hashMockUserId,
status: `${UserRegisterStatus.REGISTERER}`,
})
.reply(200);
.reply(200)
await chai.request(`${HTTP_SERVER}`)
await chai
.request(`${HTTP_SERVER}`)
.get('/api/user')
.set('content-type', 'application/json')
.query({
state: mockState,
code: mockCode,
})
.then(res => {
expect(res).to.have.status(200);
.then((res) => {
expect(res).to.have.status(200)
})
})
it('/api/login, registered user with server wallet', async () => {
prepareUserLoginTwitterApiMock(mockUserId2, mockCode2, "access-token2")
prepareUserLoginTwitterApiMock(mockUserId2, mockCode2, 'access-token2')
const wallet = TransactionManager.wallet
const signMsg = await wallet.signMessage(hashMockUserId2)
nock(`${CLIENT_URL}`)
@@ -331,63 +332,67 @@ describe('LOGIN /login', () => {
.query({
code: hashMockUserId2,
status: `${UserRegisterStatus.REGISTERER_SERVER}`,
signMsg: signMsg
signMsg: signMsg,
})
.reply(200);
.reply(200)
await chai.request(`${HTTP_SERVER}`)
await chai
.request(`${HTTP_SERVER}`)
.get('/api/user')
.set('content-type', 'application/json')
.query({
state: mockState,
code: mockCode2,
})
.then(res => {
expect(res).to.have.status(200);
.then((res) => {
expect(res).to.have.status(200)
})
})
})
function prepareUserLoginTwitterApiMock(userId: string, code: string, accessToken: string) {
nock(TWITTER_API, { "encodedQueryParams": true })
function prepareUserLoginTwitterApiMock(
userId: string,
code: string,
accessToken: string
) {
nock(TWITTER_API, { encodedQueryParams: true })
.post('/2/oauth2/token')
.query({
code: code,
grant_type: "authorization_code",
grant_type: 'authorization_code',
code_verifier: /^.*$/,
client_id: TWITTER_CLIENT_ID,
redirect_uri: /^.*$/
redirect_uri: /^.*$/,
})
.matchHeader('content-type', 'application/x-www-form-urlencoded')
.matchHeader('authorization', `Basic ${token}`)
.reply(200, {
"token_type": "bearer",
"refresh_token": 'mock-refresh-token',
"access_token": accessToken
});
token_type: 'bearer',
refresh_token: 'mock-refresh-token',
access_token: accessToken,
})
nock(TWITTER_API)
.post('/2/oauth2/token')
.query({
client_id: TWITTER_CLIENT_ID,
grant_type: 'refresh_token',
refresh_token: 'mock-refresh-token'
refresh_token: 'mock-refresh-token',
})
.matchHeader('Content-type', 'application/x-www-form-urlencoded')
.matchHeader('Authorization', `Basic ${token}`)
.reply(200, {
"access_token": accessToken
});
access_token: accessToken,
})
nock(TWITTER_API, { "encodedQueryParams": true })
nock(TWITTER_API, { encodedQueryParams: true })
.get('/2/users/me')
.matchHeader('Authorization', `Bearer ${accessToken}`)
.reply(200, {
"data": {
"id": userId,
"name": "SocialTWDev",
"username": "SocialTWDev"
}
});
data: {
id: userId,
name: 'SocialTWDev',
username: 'SocialTWDev',
},
})
}