diff --git a/packages/insomnia-app/app/models/__tests__/request.test.js b/packages/insomnia-app/app/models/__tests__/request.test.js index 4023d7883..b3dae19ff 100644 --- a/packages/insomnia-app/app/models/__tests__/request.test.js +++ b/packages/insomnia-app/app/models/__tests__/request.test.js @@ -180,8 +180,8 @@ describe('migrate()', () => { body: { mimeType: 'application/x-www-form-urlencoded', params: [ - {name: 'foo', value: 'bar', disabled: false}, - {name: 'baz', value: '{{ hello }}', disabled: false} + {name: 'foo', value: 'bar'}, + {name: 'baz', value: '{{ hello }}'} ] }, url: '' @@ -201,8 +201,8 @@ describe('migrate()', () => { body: { mimeType: 'application/x-www-form-urlencoded', params: [ - {name: 'foo', value: 'bar', disabled: false}, - {name: 'baz', value: '{{ hello }}', disabled: false} + {name: 'foo', value: 'bar'}, + {name: 'baz', value: '{{ hello }}'} ] }, url: '' @@ -222,7 +222,7 @@ describe('migrate()', () => { body: { mimeType: 'application/x-www-form-urlencoded', params: [ - {name: '{"foo": "bar"}', value: '', disabled: false} + {name: '{"foo": "bar"}', value: ''} ] }, url: '' diff --git a/packages/insomnia-app/app/models/request-version.js b/packages/insomnia-app/app/models/request-version.js index 2f5c6e511..ed0448d08 100644 --- a/packages/insomnia-app/app/models/request-version.js +++ b/packages/insomnia-app/app/models/request-version.js @@ -7,13 +7,14 @@ export const type = 'RequestVersion'; export const prefix = 'rvr'; export const canDuplicate = false; -const FIELDS_TO_IGNORE_IN_REQUEST_DIFF = [ +const FIELDS_TO_IGNORE = [ '_id', 'type', 'created', 'modified', 'metaSortKey', 'description', + 'parentId', 'name' ]; @@ -65,8 +66,15 @@ export async function restore (requestVersionId) { return null; } - const request = decompressObject(requestVersion.compressedRequest); - return models.request.update(request); + const requestPatch = decompressObject(requestVersion.compressedRequest); + const originalRequest = await models.request.getById(requestPatch._id); + + // Only restore fields that aren't blacklisted + for (const field of FIELDS_TO_IGNORE) { + delete requestPatch[field]; + } + + return models.request.update(originalRequest, requestPatch); } function _diffRequests (rOld, rNew) { @@ -76,7 +84,7 @@ function _diffRequests (rOld, rNew) { for (const key of Object.keys(rOld)) { // Skip fields that aren't useful - if (FIELDS_TO_IGNORE_IN_REQUEST_DIFF.includes(key)) { + if (FIELDS_TO_IGNORE.includes(key)) { continue; } diff --git a/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-authorization-code.test.js b/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-authorization-code.test.js index 50df83626..2c15d360d 100644 --- a/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-authorization-code.test.js +++ b/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-authorization-code.test.js @@ -52,10 +52,10 @@ describe('authorization_code', () => { body: { mimeType: 'application/x-www-form-urlencoded', params: [ - {name: 'grant_type', value: 'authorization_code', disabled: false}, - {name: 'code', value: 'code_123', disabled: false}, - {name: 'redirect_uri', value: REDIRECT_URI, disabled: false}, - {name: 'state', value: STATE, disabled: false} + {name: 'grant_type', value: 'authorization_code'}, + {name: 'code', value: 'code_123'}, + {name: 'redirect_uri', value: REDIRECT_URI}, + {name: 'state', value: STATE} ] }, headers: [ @@ -113,12 +113,12 @@ describe('authorization_code', () => { body: { mimeType: 'application/x-www-form-urlencoded', params: [ - {name: 'grant_type', value: 'authorization_code', disabled: false}, - {name: 'code', value: 'code_123', disabled: false}, - {name: 'redirect_uri', value: REDIRECT_URI, disabled: false}, - {name: 'state', value: STATE, disabled: false}, - {name: 'client_id', value: CLIENT_ID, disabled: false}, - {name: 'client_secret', value: CLIENT_SECRET, disabled: false} + {name: 'grant_type', value: 'authorization_code'}, + {name: 'code', value: 'code_123'}, + {name: 'redirect_uri', value: REDIRECT_URI}, + {name: 'state', value: STATE}, + {name: 'client_id', value: CLIENT_ID}, + {name: 'client_secret', value: CLIENT_SECRET} ] }, headers: [ diff --git a/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-client-credentials.test.js b/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-client-credentials.test.js index 772d513ea..eda8bcaca 100644 --- a/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-client-credentials.test.js +++ b/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-client-credentials.test.js @@ -44,8 +44,8 @@ describe('client_credentials', () => { body: { mimeType: 'application/x-www-form-urlencoded', params: [ - {name: 'grant_type', value: 'client_credentials', disabled: false}, - {name: 'scope', value: SCOPE, disabled: false} + {name: 'grant_type', value: 'client_credentials'}, + {name: 'scope', value: SCOPE} ] }, headers: [ @@ -98,10 +98,10 @@ describe('client_credentials', () => { body: { mimeType: 'application/x-www-form-urlencoded', params: [ - {name: 'grant_type', value: 'client_credentials', disabled: false}, - {name: 'scope', value: SCOPE, disabled: false}, - {name: 'client_id', value: CLIENT_ID, disabled: false}, - {name: 'client_secret', value: CLIENT_SECRET, disabled: false} + {name: 'grant_type', value: 'client_credentials'}, + {name: 'scope', value: SCOPE}, + {name: 'client_id', value: CLIENT_ID}, + {name: 'client_secret', value: CLIENT_SECRET} ] }, headers: [ diff --git a/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-password.test.js b/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-password.test.js index 93d2e3001..3e2138a29 100644 --- a/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-password.test.js +++ b/packages/insomnia-app/app/network/o-auth-2/__tests__/grant-password.test.js @@ -48,10 +48,10 @@ describe('password', () => { body: { mimeType: 'application/x-www-form-urlencoded', params: [ - {name: 'grant_type', value: 'password', disabled: false}, - {name: 'username', value: USERNAME, disabled: false}, - {name: 'password', value: PASSWORD, disabled: false}, - {name: 'scope', value: SCOPE, disabled: false} + {name: 'grant_type', value: 'password'}, + {name: 'username', value: USERNAME}, + {name: 'password', value: PASSWORD}, + {name: 'scope', value: SCOPE} ] }, headers: [ @@ -107,12 +107,12 @@ describe('password', () => { body: { mimeType: 'application/x-www-form-urlencoded', params: [ - {name: 'grant_type', value: 'password', disabled: false}, - {name: 'username', value: USERNAME, disabled: false}, - {name: 'password', value: PASSWORD, disabled: false}, - {name: 'scope', value: SCOPE, disabled: false}, - {name: 'client_id', value: CLIENT_ID, disabled: false}, - {name: 'client_secret', value: CLIENT_SECRET, disabled: false} + {name: 'grant_type', value: 'password'}, + {name: 'username', value: USERNAME}, + {name: 'password', value: PASSWORD}, + {name: 'scope', value: SCOPE}, + {name: 'client_id', value: CLIENT_ID}, + {name: 'client_secret', value: CLIENT_SECRET} ] }, headers: [