Browse Source

refactor: revert auth apis path

pull/6644/head
Pranav C 12 months ago
parent
commit
d1a1dd8f42
  1. 2
      packages/nocodb/src/controllers/auth/ui/auth/emailVerify.ts
  2. 2
      packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts
  3. 6
      packages/nocodb/src/run/testDocker.ts
  4. 2
      packages/nocodb/src/services/base-users/ui/auth/emailVerify.ts
  5. 2
      packages/nocodb/tests/unit/factory/user.ts
  6. 10
      packages/nocodb/tests/unit/rest/tests/attachment.test.ts
  7. 28
      packages/nocodb/tests/unit/rest/tests/auth.test.ts
  8. 6
      packages/nocodb/tests/unit/rest/tests/org.test.ts
  9. 6
      tests/playwright/setup/index.ts

2
packages/nocodb/src/controllers/auth/ui/auth/emailVerify.ts

@ -53,7 +53,7 @@ export default `<!DOCTYPE html>
methods: {},
async created() {
try {
const valid = (await axios.post('<%- baseUrl %>/api/v1/db/auth/email/validate/' + this.token)).data;
const valid = (await axios.post('<%- baseUrl %>/api/v1/auth/email/validate/' + this.token)).data;
this.valid = !!valid;
} catch (e) {
this.valid = false;

2
packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts

@ -162,7 +162,7 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate {
[
'/auth/user/me',
'/api/v1/db/auth/user/me',
'/api/v2/auth/user/me',
'/api/v1/auth/user/me',
'/api/v1/db/meta/plugins/webhook',
'/api/v2/meta/plugins/webhook',
].some((userMePath) => req.route.path === userMePath) &&

6
packages/nocodb/src/run/testDocker.ts

@ -32,7 +32,7 @@ process.env[`NC_ALLOW_LOCAL_HOOKS`] = 'true';
let admin_response;
if (!(await User.getByEmail('user@nocodb.com'))) {
admin_response = await axios.post(
`http://localhost:${process.env.PORT || 8080}/api/v1/db/auth/user/signup`,
`http://localhost:${process.env.PORT || 8080}/api/v1/auth/user/signup`,
{
email: 'user@nocodb.com',
password: 'Password123.',
@ -46,7 +46,7 @@ process.env[`NC_ALLOW_LOCAL_HOOKS`] = 'true';
const response = await axios.post(
`http://localhost:${
process.env.PORT || 8080
}/api/v1/db/auth/user/signup`,
}/api/v1/auth/user/signup`,
{
email: `user-${i}@nocodb.com`,
password: 'Password123.',
@ -55,7 +55,7 @@ process.env[`NC_ALLOW_LOCAL_HOOKS`] = 'true';
console.log(response.data);
const user = await axios.get(
`http://localhost:${process.env.PORT || 8080}/api/v1/db/auth/user/me`,
`http://localhost:${process.env.PORT || 8080}/api/v1/auth/user/me`,
{
headers: {
'xc-auth': response.data.token,

2
packages/nocodb/src/services/base-users/ui/auth/emailVerify.ts

@ -53,7 +53,7 @@ export default `<!DOCTYPE html>
methods: {},
async created() {
try {
const valid = (await axios.post('<%- baseUrl %>/api/v1/db/auth/email/validate/' + this.token)).data;
const valid = (await axios.post('<%- baseUrl %>/api/v1/auth/email/validate/' + this.token)).data;
this.valid = !!valid;
} catch (e) {
this.valid = false;

2
packages/nocodb/tests/unit/factory/user.ts

@ -9,7 +9,7 @@ const defaultUserArgs = {
const createUser = async (context, userArgs = {}) => {
const args = { ...defaultUserArgs, ...userArgs };
const response = await request(context.app)
.post('/api/v1/db/auth/user/signup')
.post('/api/v1/auth/user/signup')
.send(args);
const user = await User.getByEmail(args.email);
return { token: response.body.token, user };

10
packages/nocodb/tests/unit/rest/tests/attachment.test.ts

@ -53,7 +53,7 @@ function attachmentTests() {
};
const signupResponse = await request(context.app)
.post('/api/v1/db/auth/user/signup')
.post('/api/v1/auth/user/signup')
.send(args)
.expect(200);
@ -75,7 +75,7 @@ function attachmentTests() {
};
await request(context.app)
.post('/api/v1/db/auth/user/signup')
.post('/api/v1/auth/user/signup')
.send(args)
.expect(200);
@ -98,7 +98,7 @@ function attachmentTests() {
.expect(200);
const signinResponse = await request(context.app)
.post('/api/v1/db/auth/user/signin')
.post('/api/v1/auth/user/signin')
// pass empty data in await request
.send(args)
.expect(200);
@ -124,7 +124,7 @@ function attachmentTests() {
};
await request(context.app)
.post('/api/v1/db/auth/user/signup')
.post('/api/v1/auth/user/signup')
.send(args)
.expect(200);
@ -146,7 +146,7 @@ function attachmentTests() {
// signin to get user token
const signinResponse = await request(context.app)
.post('/api/v1/db/auth/user/signin')
.post('/api/v1/auth/user/signin')
// pass empty data in await request
.send(args)
.expect(200);

28
packages/nocodb/tests/unit/rest/tests/auth.test.ts

@ -36,7 +36,7 @@ function authTests() {
it('Signup with valid email', async () => {
const response = await request(context.app)
.post('/api/v1/db/auth/user/signup')
.post('/api/v1/auth/user/signup')
.send({ email: 'new@example.com', password: defaultUserArgs.password })
.expect(200);
@ -46,21 +46,21 @@ function authTests() {
it('Signup with invalid email', async () => {
await request(context.app)
.post('/api/v1/db/auth/user/signup')
.post('/api/v1/auth/user/signup')
.send({ email: 'test', password: defaultUserArgs.password })
.expect(400);
});
it('Signup with invalid passsword', async () => {
await request(context.app)
.post('/api/v1/db/auth/user/signup')
.post('/api/v1/auth/user/signup')
.send({ email: defaultUserArgs.email, password: 'weakpass' })
.expect(400);
});
it('Signin with valid credentials', async () => {
const response = await request(context.app)
.post('/api/v1/db/auth/user/signin')
.post('/api/v1/auth/user/signin')
.send({
email: defaultUserArgs.email,
password: defaultUserArgs.password,
@ -72,7 +72,7 @@ function authTests() {
it('Signin without email and password', async () => {
await request(context.app)
.post('/api/v1/db/auth/user/signin')
.post('/api/v1/auth/user/signin')
// pass empty data in await request
.send({})
.expect(401);
@ -80,21 +80,21 @@ function authTests() {
it('Signin with invalid credentials', async () => {
await request(context.app)
.post('/api/v1/db/auth/user/signin')
.post('/api/v1/auth/user/signin')
.send({ email: 'abc@abc.com', password: defaultUserArgs.password })
.expect(400);
});
it('Signin with invalid password', async () => {
await request(context.app)
.post('/api/v1/db/auth/user/signin')
.post('/api/v1/auth/user/signin')
.send({ email: defaultUserArgs.email, password: 'wrongPassword' })
.expect(400);
});
it('me without token', async () => {
const response = await request(context.app)
.get('/api/v1/db/auth/user/me')
.get('/api/v1/auth/user/me')
.unset('xc-auth')
.expect(200);
@ -105,7 +105,7 @@ function authTests() {
it('me with token', async () => {
const response = await request(context.app)
.get('/api/v1/db/auth/user/me')
.get('/api/v1/auth/user/me')
.set('xc-auth', context.token)
.expect(200);
@ -115,7 +115,7 @@ function authTests() {
it('Forgot password with a non-existing email id', async () => {
await request(context.app)
.post('/api/v1/db/auth/password/forgot')
.post('/api/v1/auth/password/forgot')
.send({ email: 'nonexisting@email.com' })
.expect(400);
});
@ -125,7 +125,7 @@ function authTests() {
it('Change password', async () => {
await request(context.app)
.post('/api/v1/db/auth/password/change')
.post('/api/v1/auth/password/change')
.set('xc-auth', context.token)
.send({
currentPassword: defaultUserArgs.password,
@ -136,7 +136,7 @@ function authTests() {
it('Change password - after logout', async () => {
await request(context.app)
.post('/api/v1/db/auth/password/change')
.post('/api/v1/auth/password/change')
.unset('xc-auth')
.send({
currentPassword: defaultUserArgs.password,
@ -148,14 +148,14 @@ function authTests() {
// todo:
it('Reset Password with an invalid token', async () => {
await request(context.app)
.post('/api/v1/db/auth/password/reset/someRandomValue')
.post('/api/v1/auth/password/reset/someRandomValue')
.send({ email: defaultUserArgs.email })
.expect(400);
});
it('Email validate with an invalid token', async () => {
await request(context.app)
.post('/api/v1/db/auth/email/validate/someRandomValue')
.post('/api/v1/auth/email/validate/someRandomValue')
.send({ email: defaultUserArgs.email })
.expect(400);
});

6
packages/nocodb/tests/unit/rest/tests/org.test.ts

@ -185,7 +185,7 @@ function authTests() {
.expect(200);
const failedRes = await request(context.app)
.post('/api/v1/db/auth/user/signup')
.post('/api/v1/auth/user/signup')
.send(args)
.expect(400);
@ -201,7 +201,7 @@ function authTests() {
.expect(200);
const successRes = await request(context.app)
.post('/api/v1/db/auth/user/signup')
.post('/api/v1/auth/user/signup')
.send(args)
.expect(200);
@ -211,7 +211,7 @@ function authTests() {
.to.be.a('string');
const userMeRes = await request(context.app)
.get('/api/v1/db/auth/user/me')
.get('/api/v1/auth/user/me')
.set('xc-auth', successRes.body.token)
.expect(200);

6
tests/playwright/setup/index.ts

@ -183,12 +183,12 @@ async function localInit({
// Login as root user
if (isSuperUser) {
// required for configuring license key settings
response = await axios.post('http://localhost:8080/api/v1/db/auth/user/signin', {
response = await axios.post('http://localhost:8080/api/v1/auth/user/signin', {
email: `user@nocodb.com`,
password: getDefaultPwd(),
});
} else {
response = await axios.post('http://localhost:8080/api/v1/db/auth/user/signin', {
response = await axios.post('http://localhost:8080/api/v1/auth/user/signin', {
email: `user-${parallelId}@nocodb.com`,
password: getDefaultPwd(),
});
@ -384,7 +384,7 @@ const setup = async ({
const token = response.data.token;
try {
const admin = await axios.post('http://localhost:8080/api/v1/db/auth/user/signin', {
const admin = await axios.post('http://localhost:8080/api/v1/auth/user/signin', {
email: `user@nocodb.com`,
password: getDefaultPwd(),
});

Loading…
Cancel
Save