Skip to content

Commit

Permalink
fix(pacer): Prevents error by checking filingCookie existence
Browse files Browse the repository at this point in the history
  • Loading branch information
ERosendo committed Jun 25, 2024
1 parent 9581696 commit 64e104a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Features:
- Inserts the RECAP button and [R] icons to the ACMS Docket report. ([#374](https://github.com/freelawproject/recap-chrome/pull/374))
- Displays the warning about combined PDFs on the download page.([#376](https://github.com/freelawproject/recap-chrome/pull/376))
- Introduces logic to upload ACMS attachment pages to CourtListener([#375](https://github.com/freelawproject/recap-chrome/pull/375))
- Introduces validation for the cookie used to identify filing account users.([#371](https://github.com/freelawproject/recap/issues/371), [#377](https://github.com/freelawproject/recap-chrome/pull/377)).

Changes:
- None yet
Expand Down
25 changes: 25 additions & 0 deletions spec/PacerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,31 @@ describe('The PACER module', function () {
});
});

describe('hasFilingCookie', function () {
const filingAccountCookie =
'PacerSession=B7yuvmcj2F...9p5nDzEXsHE; ' + 'isFilingAccount=true';
const nonFilingAccountCookie =
'PacerUser=B7yuvmcj2F...9p5nDzEXsHE; ' + 'PacerPref=receipt=Y';
const nonLoggedInCookie = 'PacerSession=unvalidated; PacerPref=receipt=Y';
const nonsenseCookie = 'Foo=barbaz; Baz=bazbar; Foobar=Foobar';

it('returns true for a valid cookie from a filing account', function () {
expect(PACER.hasFilingCookie(filingAccountCookie)).toBe(true);
});

it('returns false for cookies from a non-filing account', function () {
expect(PACER.hasFilingCookie(nonFilingAccountCookie)).toBe(false);
});

it('returns false for a non-logged in cookie', function () {
expect(PACER.hasFilingCookie(nonLoggedInCookie)).toBe(false);
});

it('returns false for nonsense cookie', function () {
expect(PACER.hasFilingCookie(nonsenseCookie)).toBe(false);
});
});

describe('isAppellateCourt', function () {
it('returns true for an appellate court', function () {
expect(PACER.isAppellateCourt('ca5')).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion src/pacer.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ let PACER = {
let filingCookie = cookieString.split('; ')
.find((row) => row.startsWith('isFilingAccount'))
?.split('=')[1];
return !!filingCookie.match(/true/);
return !!(filingCookie && filingCookie.match(/true/));
},

// Returns true if the given court identifier is for an appellate court.
Expand Down

0 comments on commit 64e104a

Please sign in to comment.