123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import {Request} from 'sentry/components/events/interfaces/request';
- import {EntryRequest, EntryType} from 'sentry/types/event';
- describe('Request entry', function () {
- it('display redacted data', async function () {
- const event = {
- ...TestStubs.Event(),
- entries: [
- {
- type: 'request',
- data: {
- env: {
- DOCUMENT_ROOT: '',
- REMOTE_ADDR: '',
- SERVER_NAME: '',
- SERVER_PORT: '',
- },
- method: 'POST',
- query: [],
- url: '/Home/PostIndex',
- inferredContentType: null,
- fragment: null,
- headers: [],
- cookies: [],
- data: [
- {
- a: '',
- c: [
- {
- d: '',
- f: '',
- },
- ],
- },
- ],
- },
- },
- ],
- _meta: {
- entries: {
- 0: {
- data: {
- '': null,
- method: null,
- url: null,
- query: null,
- data: {
- a: {
- '': {
- rem: [['project:3', 's', 0, 0]],
- len: 1,
- chunks: [
- {
- type: 'redaction',
- text: '',
- rule_id: 'project:3',
- remark: 's',
- },
- ],
- },
- },
- c: {
- 0: {
- d: {
- '': {
- rem: [['project:3', 's', 0, 0]],
- len: 1,
- chunks: [
- {
- type: 'redaction',
- text: '',
- rule_id: 'project:3',
- remark: 's',
- },
- ],
- },
- },
- f: {
- '': {
- rem: [['project:3', 's', 0, 0]],
- len: 1,
- chunks: [
- {
- type: 'redaction',
- text: '',
- rule_id: 'project:3',
- remark: 's',
- },
- ],
- },
- },
- },
- },
- },
- env: {
- DOCUMENT_ROOT: {
- '': {
- rem: [['project:3', 's', 0, 0]],
- len: 78,
- chunks: [
- {
- type: 'redaction',
- text: '',
- rule_id: 'project:3',
- remark: 's',
- },
- ],
- },
- },
- REMOTE_ADDR: {
- '': {
- rem: [['project:3', 's', 0, 0]],
- len: 3,
- chunks: [
- {
- type: 'redaction',
- text: '',
- rule_id: 'project:3',
- remark: 's',
- },
- ],
- },
- },
- SERVER_NAME: {
- '': {
- rem: [['project:3', 's', 0, 0]],
- len: 7,
- chunks: [
- {
- type: 'redaction',
- text: '',
- rule_id: 'project:3',
- remark: 's',
- },
- ],
- },
- },
- SERVER_PORT: {
- '': {
- rem: [['project:3', 's', 0, 0]],
- len: 5,
- chunks: [
- {
- type: 'redaction',
- text: '',
- rule_id: 'project:3',
- remark: 's',
- },
- ],
- },
- },
- },
- },
- },
- },
- },
- };
- render(<Request event={event} data={event.entries[0].data} />);
- expect(screen.getAllByText(/redacted/)).toHaveLength(5);
- userEvent.click(await screen.findByLabelText('Expand'));
- expect(screen.getAllByText(/redacted/)).toHaveLength(7);
- userEvent.hover(screen.getAllByText(/redacted/)[0]);
- expect(
- await screen.findByText('Replaced because of PII rule "project:3"')
- ).toBeInTheDocument(); // tooltip description
- });
- describe('getBodySection', function () {
- it('should return plain-text when given unrecognized inferred Content-Type', function () {
- const data: EntryRequest['data'] = {
- query: [],
- data: 'helloworld',
- headers: [],
- cookies: [],
- env: {},
- inferredContentType: null,
- method: 'POST',
- url: '/Home/PostIndex',
- fragment: null,
- };
- const event = {
- ...TestStubs.Event(),
- entries: [
- {
- type: EntryType.REQUEST,
- data,
- },
- ],
- };
- render(<Request event={event} data={event.entries[0].data} />);
- expect(
- screen.getByTestId('rich-http-content-body-section-pre')
- ).toBeInTheDocument();
- });
- it('should return a KeyValueList element when inferred Content-Type is x-www-form-urlencoded', function () {
- const data: EntryRequest['data'] = {
- query: [],
- data: {foo: ['bar'], bar: ['baz']},
- headers: [],
- cookies: [],
- env: {},
- inferredContentType: 'application/x-www-form-urlencoded',
- method: 'POST',
- url: '/Home/PostIndex',
- fragment: null,
- };
- const event = {
- ...TestStubs.Event(),
- entries: [
- {
- type: EntryType.REQUEST,
- data,
- },
- ],
- };
- render(<Request event={event} data={event.entries[0].data} />);
- expect(
- screen.getByTestId('rich-http-content-body-key-value-list')
- ).toBeInTheDocument();
- });
- it('should return a ContextData element when inferred Content-Type is application/json', function () {
- const data: EntryRequest['data'] = {
- query: [],
- data: {foo: 'bar'},
- headers: [],
- cookies: [],
- env: {},
- inferredContentType: 'application/json',
- method: 'POST',
- url: '/Home/PostIndex',
- fragment: null,
- };
- const event = {
- ...TestStubs.Event(),
- entries: [
- {
- type: EntryType.REQUEST,
- data,
- },
- ],
- };
- render(<Request event={event} data={event.entries[0].data} />);
- expect(
- screen.getByTestId('rich-http-content-body-context-data')
- ).toBeInTheDocument();
- });
- it('should not blow up in a malformed uri', function () {
- // > decodeURIComponent('a%AFc')
- // URIError: URI malformed
- const data: EntryRequest['data'] = {
- query: 'a%AFc',
- data: '',
- headers: [],
- cookies: [],
- env: {},
- method: 'POST',
- url: '/Home/PostIndex',
- fragment: null,
- };
- const event = {
- ...TestStubs.Event(),
- entries: [
- {
- type: EntryType.REQUEST,
- data,
- },
- ],
- };
- expect(() =>
- render(<Request event={event} data={event.entries[0].data} />)
- ).not.toThrow();
- });
- it("should not cause an invariant violation if data.data isn't a string", function () {
- const data: EntryRequest['data'] = {
- query: [],
- data: [{foo: 'bar', baz: 1}],
- headers: [],
- cookies: [],
- env: {},
- method: 'POST',
- url: '/Home/PostIndex',
- fragment: null,
- };
- const event = {
- ...TestStubs.Event(),
- entries: [
- {
- type: EntryType.REQUEST,
- data,
- },
- ],
- };
- expect(() =>
- render(<Request event={event} data={event.entries[0].data} />)
- ).not.toThrow();
- });
- });
- });
|