🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

govuk_personalisation

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

govuk_personalisation

bundlerRubygems
Version
1.1.0
Version published
Maintainers
1
Created
Source

GOV.UK Personalisation

A gem to hold shared code which other GOV.UK apps use to implement accounts-related functionality.

Installation

Add this line to your application's Gemfile:

gem 'govuk_personalisation'

And then execute:

$ bundle install

Usage

Rails concern

Include the concern into a controller:

include GovukPersonalisation::AccountConcern

And it will add before_action methods to:

  • fetch the account session identifier from the request headers, making it available as account_session_header
  • set a Vary response header, to ensure responses for different users are cached differently by the CDN

The following functions are available:

  • logged_in? - check if there is an account session header
  • set_account_session_header - replace the current session value, and set the response header the CDN uses to update the user's cookie
  • logout! - clear the session value, and set the response header the CDN uses to remove the user's cookie

When run in development mode (RAILS_ENV=development), a cookie on dev.gov.uk is used instead of custom headers.

Test helpers

There are test helpers for both request and feature specs to log the user in. Include the relevant helper:

include GovukPersonalisation::TestHelpers::Requests

or

include GovukPersonalisation::TestHelpers::Features

And then log the user in:

before do
  mock_logged_in_session
end

If you need a specific session identifier, for example to match against it in WebMock stubs or with the gds-api-adapters test helpers, you can pass it as an argument:

before do
  mock_logged_in_session("your-session-identifier-goes-here")
end

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 18 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts