Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#186415584 : Fix MoesifSetting lookup issue, Governance rule headers override #80

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

qmjava
Copy link
Contributor

@qmjava qmjava commented Nov 7, 2023

Pull Request review Checklist:

  • Follows guidelines for public repo ?
  • README updated, if required ?
  • Release Version updated ?
  • User Agent Version updated ?
  • Includes tests conducted and test result in the ticket and/or QA doc ?
  • Does NOT include code from others? (Unintended consequence of a bad merge) ?

@qmjava
Copy link
Contributor Author

qmjava commented Nov 7, 2023

npm run test:events

[email protected] test:events /Users/xiaokanghuo/dev/governance-rules-tests
cross-env RUN_TYPE=EVENTS mocha --require @babel/register

hereEVENTShttps://api.moesif.net

Test sending events with rule from Case 1, apply to: matching, apply to unidentified: true
get error back altuog
Error: Forbidden
at Request.callback (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/index.js:901:17)
at IncomingMessage. (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/index.js:1166:18)
at IncomingMessage.emit (events.js:412:35)
at endReadableNT (internal/streams/readable.js:1333:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
status: 403,
response: <ref *1> Response {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
res: IncomingMessage {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 4,
_maxListeners: undefined,
socket: [Socket],
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers: [Object],
rawHeaders: [Array],
trailers: {},
rawTrailers: [],
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 403,
statusMessage: 'Forbidden',
client: [Socket],
_consuming: true,
_dumped: false,
req: [ClientRequest],
text: '{\n "your_city": "rome",\n "your_country": "italy"\n}',
[Symbol(kCapture)]: false,
[Symbol(RequestTimeout)]: undefined
},
request: Request {
_events: [Object: null prototype],
_eventsCount: 1,
_maxListeners: undefined,
_enableHttp2: false,
_agent: false,
_formData: null,
method: 'GET',
url: 'https://localhost:5002/gov/no_italy',
_header: [Object],
header: [Object],
writable: true,
_redirects: 0,
_maxRedirects: 5,
cookies: '',
qs: {},
_query: [],
qsRaw: [],
_redirectList: [],
_streamRequest: false,
_lookup: undefined,
req: [ClientRequest],
protocol: 'http:',
host: 'localhost:5002',
_endCalled: true,
_callback: [Function (anonymous)],
_fullfilledPromise: [Promise],
res: [IncomingMessage],
_resBuffered: true,
response: [Circular *1],
called: true,
[Symbol(kCapture)]: false
},
req: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Socket],
_header: 'GET /gov/no_italy HTTP/1.1\r\n' +
'Host: localhost:5002\r\n' +
'Accept-Encoding: gzip, deflate\r\n' +
'X-User-Id: rome1\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/gov/no_italy',
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'localhost',
protocol: 'http:',
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
text: '{\n "your_city": "rome",\n "your_country": "italy"\n}',
files: undefined,
buffered: true,
headers: {
connection: 'close',
date: 'Tue, 07 Nov 2023 01:08:39 GMT',
server: 'Kestrel',
'transfer-encoding': 'chunked',
'x-moesif-transaction-id': 'b632c4c0-aa3c-4ec3-9624-f63b7449dab3',
'x-test-header': 'blocked for italy case 1 rule',
'x-user-rule': 'applied block italy users and unidentified users'
},
header: {
connection: 'close',
date: 'Tue, 07 Nov 2023 01:08:39 GMT',
server: 'Kestrel',
'transfer-encoding': 'chunked',
'x-moesif-transaction-id': 'b632c4c0-aa3c-4ec3-9624-f63b7449dab3',
'x-test-header': 'blocked for italy case 1 rule',
'x-user-rule': 'applied block italy users and unidentified users'
},
statusCode: 403,
status: 403,
statusType: 4,
info: false,
ok: false,
redirect: false,
clientError: true,
serverError: false,
error: Error: cannot GET /gov/no_italy (403)
at Response.toError (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/response.js:110:17)
at Response._setStatusProperties (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/response-base.js:107:48)
at new Response (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/response.js:41:8)
at Request._emitResponse (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/index.js:953:20)
at IncomingMessage. (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/index.js:1166:38)
at IncomingMessage.emit (events.js:412:35)
at endReadableNT (internal/streams/readable.js:1333:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
status: 403,
text: '{\n "your_city": "rome",\n "your_country": "italy"\n}',
method: 'GET',
path: '/gov/no_italy'
},
created: false,
accepted: false,
noContent: false,
badRequest: false,
unauthorized: false,
notAcceptable: false,
forbidden: true,
notFound: false,
unprocessableEntity: false,
type: '',
links: {},
setEncoding: [Function: bound ],
redirects: [],
pipe: [Function (anonymous)],
[Symbol(kCapture)]: false
}
}
{"connection":"close","date":"Tue, 07 Nov 2023 01:08:39 GMT","server":"Kestrel","transfer-encoding":"chunked","x-moesif-transaction-id":"b632c4c0-aa3c-4ec3-9624-f63b7449dab3","x-test-header":"blocked for italy case 1 rule","x-user-rule":"applied block italy users and unidentified users"}
response body
{}
✔ User in cohort, regex match: apply rule (447ms)
✔ User in cohort, regex not match: no apply (282ms)
✔ user not in cohort, regex match: no apply (253ms)
✔ user not in cohort, regex not match: no apply (206ms)
✔ anonymous user, regex match: apply (216ms)
✔ anonymous user, regex not match: no apply (129ms)
✔ test an company rule not_matching, this one should be not be blocked because in cohort (371ms)
Error: Payment Required
at Request.callback (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/index.js:901:17)
at IncomingMessage. (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/index.js:1166:18)
at IncomingMessage.emit (events.js:412:35)
at endReadableNT (internal/streams/readable.js:1333:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
status: 402,
response: <ref *1> Response {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
res: IncomingMessage {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 4,
_maxListeners: undefined,
socket: [Socket],
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers: [Object],
rawHeaders: [Array],
trailers: {},
rawTrailers: [],
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 402,
statusMessage: 'Payment Required',
client: [Socket],
_consuming: true,
_dumped: false,
req: [ClientRequest],
text: '{\n "your_company_domain": "{{0}}"\n}',
[Symbol(kCapture)]: false,
[Symbol(RequestTimeout)]: undefined
},
request: Request {
_events: [Object: null prototype],
_eventsCount: 1,
_maxListeners: undefined,
_enableHttp2: false,
_agent: false,
_formData: null,
method: 'GET',
url: 'https://localhost:5002/gov/for_companies_in_japan_only',
_header: [Object],
header: [Object],
writable: true,
_redirects: 0,
_maxRedirects: 5,
cookies: '',
qs: {},
_query: [],
qsRaw: [],
_redirectList: [],
_streamRequest: false,
_lookup: undefined,
req: [ClientRequest],
protocol: 'http:',
host: 'localhost:5002',
_endCalled: true,
_callback: [Function (anonymous)],
_fullfilledPromise: [Promise],
res: [IncomingMessage],
_resBuffered: true,
response: [Circular *1],
called: true,
[Symbol(kCapture)]: false
},
req: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Socket],
_header: 'GET /gov/for_companies_in_japan_only HTTP/1.1\r\n' +
'Host: localhost:5002\r\n' +
'Accept-Encoding: gzip, deflate\r\n' +
'X-Company-Id: gov_com_01\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/gov/for_companies_in_japan_only',
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'localhost',
protocol: 'http:',
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype]
},
text: '{\n "your_company_domain": "{{0}}"\n}',
files: undefined,
buffered: true,
headers: {
connection: 'close',
date: 'Tue, 07 Nov 2023 01:08:41 GMT',
server: 'Kestrel',
'transfer-encoding': 'chunked',
'x-moesif-transaction-id': '6c6a8bf7-3f90-490c-a3ce-8c6642a6098e',
'x-company-block-header': 'companies hq not in japan cohort'
},
header: {
connection: 'close',
date: 'Tue, 07 Nov 2023 01:08:41 GMT',
server: 'Kestrel',
'transfer-encoding': 'chunked',
'x-moesif-transaction-id': '6c6a8bf7-3f90-490c-a3ce-8c6642a6098e',
'x-company-block-header': 'companies hq not in japan cohort'
},
statusCode: 402,
status: 402,
statusType: 4,
info: false,
ok: false,
redirect: false,
clientError: true,
serverError: false,
error: Error: cannot GET /gov/for_companies_in_japan_only (402)
at Response.toError (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/response.js:110:17)
at Response._setStatusProperties (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/response-base.js:107:48)
at new Response (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/response.js:41:8)
at Request._emitResponse (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/index.js:953:20)
at IncomingMessage. (/Users/xiaokanghuo/dev/governance-rules-tests/node_modules/superagent/src/node/index.js:1166:38)
at IncomingMessage.emit (events.js:412:35)
at endReadableNT (internal/streams/readable.js:1333:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
status: 402,
text: '{\n "your_company_domain": "{{0}}"\n}',
method: 'GET',
path: '/gov/for_companies_in_japan_only'
},
created: false,
accepted: false,
noContent: false,
badRequest: false,
unauthorized: false,
notAcceptable: false,
forbidden: false,
notFound: false,
unprocessableEntity: false,
type: '',
links: {},
setEncoding: [Function: bound ],
redirects: [],
pipe: [Function (anonymous)],
[Symbol(kCapture)]: false
}
}
✔ test an company rule not matching, this one should apply since the hq is not in japan (153ms)
✔ test an company rule not matching, one applied to unidentified companies also (236ms)
response headers
┌─────────────────────────┬────────────────────────────────────────┐
│ (index) │ Values │
├─────────────────────────┼────────────────────────────────────────┤
│ connection │ 'close' │
│ date │ 'Tue, 07 Nov 2023 01:08:41 GMT' │
│ server │ 'Kestrel' │
│ transfer-encoding │ 'chunked' │
│ x-moesif-transaction-id │ '22f11f6f-6c9a-4d99-a302-2123832a8577' │
│ x-final-rule │ 'users in paris' │
│ x-regex-rule │ 'applied multiple_match' │
│ x-company-block-header │ 'companies hq in France' │
│ x-company-rule │ 'company hq in France' │
│ x-user-block-header │ 'users from paris' │
│ x-user-rule │ 'user from paris' │
└─────────────────────────┴────────────────────────────────────────┘
Response body is
┌──────────────┬───────────────────────┐
│ (index) │ Values │
├──────────────┼───────────────────────┤
│ your_email │ '[email protected]' │
│ your_city │ 'paris' │
│ your_country │ 'France' │
└──────────────┴───────────────────────┘
✔ test multiple rules should apply, verify the user rule is the one applies, other headers are applied (246ms)

10 passing (3s)

@praves77 praves77 changed the title Fix MoesifSetting lookup issue, Governance rule headers override #186415584 : Fix MoesifSetting lookup issue, Governance rule headers override Nov 7, 2023
@praves77 praves77 merged commit 66a13b4 into master Nov 7, 2023
@praves77 praves77 deleted the merge_tag_fix branch November 7, 2023 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants