Commit Graph

2949 Commits

Author SHA1 Message Date
Rebecca Law
0e1ee504ac - Add unit test for when case when the cookie doesn't match the db.
- Move code into User.signout method to further encapsulate the code.
2020-02-03 15:08:55 +00:00
Rebecca Law
937c9f2adc Ensure that the session is logged out server side, not just client side.
Anytime a user clicks "sign out" we should be signing them out server side as well. This can be accomplished by setting the Users.current_session_id = null.
I found that the method User.logged_in_elsewhere doesn't need to check if the current_session_id is None. The current_session_ids in the cookie and db (redis or postgres) then the user should be forced to log in again.
2020-02-03 12:24:02 +00:00
Leo Hemsted
01ba256ef9 bump utils to fix datetime formatting jinja bug 2020-01-28 10:32:21 +00:00
Leo Hemsted
4e1fcfbff1 handle invalid upload errors correctly
previously it assumed that invalid_pages would always exist, however it
might be `None` if the error isn't on a specific page. Errors on
specific pages include a page not being A4 or content being outside the
boundary. Errors not on specific pages include the file not being a pdf,
or containing too many pages
2020-01-27 15:11:37 +00:00
Chris Hill-Scott
da2bc29b40 Merge pull request #3263 from alphagov/fix-new-jobs-showing-as-deleted
Use time to determine why notifications don’t exist
2020-01-24 15:27:29 +00:00
Pea M. Tyczynska
ba6b412bca Merge pull request #3268 from alphagov/proper-form-for-letter-branding
Parametrise branding request flow so it serves both email and letter branding
2020-01-23 16:50:41 +00:00
Pea Tyczynska
a578ec23a3 Redirect to template after succesful branding request
if user entered branding request flow from a template.
2020-01-23 16:35:15 +00:00
Pea M. Tyczynska
fdff9d3b83 Ensure gov.uk branding only available for emails and not for letters
Also align and statements
2020-01-23 16:34:58 +00:00
Chris Hill-Scott
3b108e8c93 Add comment clarifying timings in test case 2020-01-23 16:32:08 +00:00
Leo Hemsted
461ba32f4e Merge pull request #3274 from alphagov/one-more-thing
fix one more place where senders weren't sanitised
2020-01-23 15:38:45 +00:00
Tom Byers
d68403f7dc Merge pull request #3272 from alphagov/stop-removing-ga-cookies
Stop removing GA cookies
2020-01-23 11:32:42 +00:00
Leo Hemsted
f3fa6a67e1 fix one more place where senders weren't sanitised
make sure everything is using the `nl2br` formatter that properly wraps
it in markdown to keep everything sanitised nicely. Also write a couple
of tests
2020-01-22 17:22:01 +00:00
Tom Byers
cfdc83a336 Update tests 2020-01-22 12:26:55 +00:00
Tom Byers
174c10c7ff Clear old cookies to be based on consent
We have been clearing all the Google Analytics
cookies on each page request.

It is now possible for a user to consent to having
Google Analytics cookies so this should have been
checking for that before deleting them.

This makes that change, with tests for those
scenarios.
2020-01-22 12:14:23 +00:00
Tom Byers
98e48e68f9 Change the URL JSDOM uses for the current page
https://jestjs.io/docs/en/configuration#testurl-string

Affects all DOM APIs that return information about
the URL, for example window.location.

Why:

We now have tests for setting/deleting cookies.
Tough-cookie, the library JSDOM uses for cookie
handling cookies doesn't allow setting cookies
with `domain=localhost`. This is correct by
RFC6265, the standard it follows, as domains must
have 2 or more `.`s in them.

The only way to set a cookie on `localhost` is to
leave out the `domain` attribute.

The code we are testing sets and deletes cookies
set on specific domains so using `localhost` is
out.

We also cannot just set/delete cookies on the
domains used as cookies are required to match the
domain of the current page.

The solution we are left with is to set the
current page to one from production and make sure
each cookie is set relative to that domain.

Note: this introduces `testURL` in isolation to be
sure it doesn't break any existing tests.
2020-01-22 11:08:29 +00:00
Pea Tyczynska
5a32177982 Delete old letter branding request page 2020-01-21 16:47:42 +00:00
Pea Tyczynska
02cb6c9c38 Create a letter branding request flow to match email branding request
Test if service settings links to branding request page for letters

Parametrize all branding tests so they also work for letter branding
2020-01-21 16:47:14 +00:00
Chris Hill-Scott
291734b0c4 Merge branch 'master' into fix-new-jobs-showing-as-deleted 2020-01-21 14:24:40 +00:00
Chris Hill-Scott
d27d400f53 Test the boundary conditions
Since date math can be hard it’s good to test as close to the boundary
as possible, which hopefully catches stuff like timezone related bugs.
2020-01-21 14:15:48 +00:00
Chris Hill-Scott
f5ced76e63 Don’t mock job processing in the future
It could hide bugs or make the tests harder to understand later on if
what they’re testing is an impossible scenario.
2020-01-21 14:09:54 +00:00
Chris Hill-Scott
6ff9dac161 Merge pull request #3254 from alphagov/letter-validation-short-messages
Add separate messages for precompiled letters that have failed validation
2020-01-21 10:02:58 +00:00
Chris Hill-Scott
34f209a08b Fix mixed-up error messages
The too many pages error was being returned when the file couldn’t be
read. This commit corrects the error message, and adds a test to make
sure this case is covered.
2020-01-20 15:54:07 +00:00
Chris Hill-Scott
1fc0f58541 Add test for plural form of error message 2020-01-20 15:50:16 +00:00
Chris Hill-Scott
bc7deebcc7 Split test in two for readability 2020-01-20 15:46:03 +00:00
Chris Hill-Scott
32105b3328 Don’t assume jobs status will be present
The API response for jobs includes a field called `job_status`. The API
response for uploads doesn’t.

The `Job` mode handles uploads and jobs, so it needs to account for the
possibility of the field not being there.
2020-01-20 15:25:47 +00:00
Tom Byers
62f1c5a88e Fix associated test 2020-01-20 10:05:15 +00:00
Tom Byers
a67cd65f47 Make Google Analytics cookies expire in 1 year 2020-01-20 10:05:06 +00:00
Tom Byers
1d9c5e5da9 Default the cookie banner to be hidden
It should only be shown if JS is available and the
cookieMessage JS finds consent has not been set.
2020-01-20 10:04:58 +00:00
Tom Byers
1a97c6028c Add event tracking to window.GOVUK.analytics
app/assets/javascripts/errorTracking.js sent
events to `window.ga`.

This extends the API of `window.GOVUK.Analytics`
to include support for sending events so all
calls to `window.ga` can use it instead of direct
access.

This use of `window.ga` was missed from the
initial work on `window.GOVUK.Anaytics`.
2020-01-20 10:04:56 +00:00
Tom Byers
b17140ac46 Fix test description 2020-01-20 10:03:47 +00:00
Tom Byers
8a0d0a15a8 Hide cookie banner if no-js
Decided in discussions with @quis and @yahoopete
that users without JS available cannot
accept/reject analytics cookies so the banner has
no use.
2020-01-20 10:03:47 +00:00
Tom Byers
9a0d522964 Add JS tests for analytics & cookies JS
Includes:
- tests for the analytics interface ported from
  GOVUK Frontend Toolkit
- tests for the cookie banner that appears on all
  pages except the cookies page
- tests for the cookies page JS
- tests for the hasConsentFor function
- adding a deleteCookie helper to remove
  cookies during tests
- polyfill for insertAdjacentText

The last one is because JSDOM doesn't support
insertAdjacentText but our target browsers
do. This polyfill also includes one for
insertAdjacentHTML.
2020-01-20 10:03:36 +00:00
Tom Byers
28140104f1 Fix python tests broken by cookie banner 2020-01-20 10:03:19 +00:00
Chris Hill-Scott
87b2686875 Use time to determine why notifications don’t exist
Notifications won’t exist for a job if:
- it’s just started
- it started a long time ago (older than the retention period)

We have a bug where:
1. Job starts processing, puts notifications on queue
2. Job finishes processing, sets status to `finished`
3. First notification gets picked up off the queue and put in the
   database

In between 2. and 3. it’s possible for a job to be finished, but also to
have no notifications. We’re saying this is because the notifications
have been deleted, whereas really it’s because they haven’t been created
yet.

This commit fixes that bug by introducing the concept of recency for
jobs.

‘Recent’ is defined as 1 day, which is:
- a lot longer than it takes to create any notifications
- a bit shorter than anyone’s retention time

N.B. `processing_started` is defined here:
879ba1d5f0/app/models.py (L1194)

It can be `None` for scheduled jobs that haven’t started yet.
2020-01-17 13:27:20 +00:00
Chris Hill-Scott
a5fe50ce72 Merge pull request #3262 from alphagov/rename-model-property
Rename `client` property on `ModelLists`
2020-01-17 11:08:08 +00:00
Chris Hill-Scott
fa4fd1c896 Account for missing scheduled for field
Jobs have a `scheduled_for` field. Single letter uploads don’t.

At the moment we treat both of them as `Job`s. So the `Job` model needs
to account for when the `scheduled_for` field is missing.
2020-01-17 10:01:39 +00:00
Chris Hill-Scott
c4818eb7f2 Rename property on ModelLists
The property doesn’t represent the whole client, but just one method on
it. So this commit renames the property to better describe what it is
designed to store.
2020-01-16 16:31:20 +00:00
Chris Hill-Scott
721134dc17 Merge pull request #3251 from alphagov/job-model
Make models for individual jobs and collections of jobs
2020-01-16 15:52:21 +00:00
Leo Hemsted
66db735e09 Revert "Merge pull request #3238 from alphagov/cookies-update"
This reverts commit eec4bec761, reversing
changes made to 64480e2fff.
2020-01-15 14:40:48 +00:00
Tom Byers
b86398ddda Fix associated test 2020-01-15 12:03:44 +00:00
Chris Hill-Scott
3762daad84 Add a redirect for the letter specification
This way we have a URL we can give people that always points to the
latest version of the spec.

And it makes our code more Flask-idiomatic to be using `url_for` to be
generating a URL, rather than passing around a constant.
2020-01-15 11:54:14 +00:00
Tom Byers
eec4bec761 Merge pull request #3238 from alphagov/cookies-update
New cookies banner and page
2020-01-15 10:37:14 +00:00
Tom Byers
dce6a46df6 Make Google Analytics cookies expire in 1 year 2020-01-14 14:16:00 +00:00
Chris Hill-Scott
0b6744854b Fix test that fails 1 in 60 times
This test looks for how many times the string `50` appears in the text
of the `<main>` element of the page. The `<main>` element also contains
some times, for example 1:23pm.

This means that when the time reaches 1:50pm, 2:50pm, etc the number of
times the string `50` appears in the page changes. Which causes the test
assertions to fail.
2020-01-14 14:06:04 +00:00
Chris Hill-Scott
b57e4a0d0d Test URLs separately
It’s hard to read the tests when they have HTML bundled up with content.
So this commit:
- introduces BeautifulSoup to parse the HTML
- asserts separately on the text and any links found in the HTML
2020-01-14 13:50:22 +00:00
Chris Hill-Scott
4552587829 Merge pull request #3256 from alphagov/fix-session-bug-change-user-email
Fix session bug when changing user’s email address
2020-01-14 13:46:03 +00:00
Chris Hill-Scott
540945539b Add some summaries of letter validation errors
We show letter validation errors in two places:

1. In response to a user uploading a PDF
   Here we use the error banner pattern because the problem is as a
   direct consequence of a user’s action, and is blocking them from
   continuing.

2. Once a PDF provided through the API has been validated
   We use a less prominent pattern of red text with no border because
   the message is reporting on something that’s already happened, and
   which wasn’t a direct consequence of the user clicking something

Because the context and patterns used are different we need slightly
different content in each of these situations. Previously we tried to
reuse the same content to make the code cleaner and less repetitive. But
ultimately a clear interface trumps clear code.
2020-01-14 13:34:18 +00:00
Chris Hill-Scott
72abd89fe0 Fix indentation and trailing commas
This will make the diffs introducing substative changes easier to read.
Consistent indenting and always having trailing commas on lists and
dictionaries makes for smaller diffs.
2020-01-14 13:31:29 +00:00
Chris Hill-Scott
e3670de6c4 Remove the title from the short errors
This undoes some of the temporary work we did previously in order to
ship the new ‘address is empty’ error message.
2020-01-14 13:30:31 +00:00
Tom Byers
4a303cf0d8 Merge branch 'master' into cookies-update 2020-01-14 13:17:21 +00:00