gds-sso 22.0.0 → 22.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gds-sso/failure_app.rb +0 -6
- data/lib/gds-sso/lint/user_spec.rb +43 -23
- data/lib/gds-sso/user.rb +8 -0
- data/lib/gds-sso/version.rb +1 -1
- data/spec/unit/user_spec.rb +20 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 006b7a16f52c7a8013c5bf88cf8afeb9dbe9676a444618b80cb47c546bc8dda7
|
4
|
+
data.tar.gz: 19796282c692f14f5e5cfc6ee7dd823835d536a804470745affdd42cf1ca78c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93c40856ef0a2442e7cdca2854dff5d34c4d726a573e1dccf2bd5d81b7381d67243026a2ad00a165b6ff189c0ab15ff5cdf0e990ac0c25f00afea2c49cb0bd00
|
7
|
+
data.tar.gz: 3e9ed3c8da369905de18e35487c9d60b1a0c49663436bfff8a0e4bfeaf035914026512c47c4ca6f338c025bc878cbd1100ca0eeded22087355c0761b47057066
|
data/lib/gds-sso/failure_app.rb
CHANGED
@@ -39,12 +39,6 @@ module GDS
|
|
39
39
|
api_unauthorized("No bearer token was provided", "invalid_request")
|
40
40
|
end
|
41
41
|
|
42
|
-
# Stores requested uri to redirect the user after signing in. We cannot use
|
43
|
-
# scoped session provided by warden here, since the user is not authenticated
|
44
|
-
# yet, but we still need to store the uri based on scope, so different scopes
|
45
|
-
# would never use the same uri to redirect.
|
46
|
-
|
47
|
-
# TOTALLY NOT DOING THE SCOPE THING. PROBABLY SHOULD.
|
48
42
|
def store_location!
|
49
43
|
return unless request.get?
|
50
44
|
|
@@ -49,30 +49,50 @@ RSpec.shared_examples "a gds-sso user class" do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
specify "the User class and GDS::SSO::User mixin work together" do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
"
|
56
|
-
|
57
|
-
|
58
|
-
"extra" => {
|
59
|
-
"user" => {
|
60
|
-
"disabled" => false,
|
61
|
-
"permissions" => %w[signin],
|
62
|
-
"organisation_slug" => "cabinet-office",
|
63
|
-
"organisation_content_id" => "91e57ad9-29a3-4f94-9ab4-5e9ae6d13588",
|
52
|
+
with_anonymous_user_id_secret "some-anonymous-user-id-secret" do
|
53
|
+
auth_hash = {
|
54
|
+
"uid" => "12345",
|
55
|
+
"info" => {
|
56
|
+
"name" => "Joe Smith",
|
57
|
+
"email" => "joe.smith@example.com",
|
64
58
|
},
|
65
|
-
|
66
|
-
|
59
|
+
"extra" => {
|
60
|
+
"user" => {
|
61
|
+
"disabled" => false,
|
62
|
+
"permissions" => %w[signin],
|
63
|
+
"organisation_slug" => "cabinet-office",
|
64
|
+
"organisation_content_id" => "91e57ad9-29a3-4f94-9ab4-5e9ae6d13588",
|
65
|
+
},
|
66
|
+
},
|
67
|
+
}
|
68
|
+
|
69
|
+
user = described_class.find_for_gds_oauth(auth_hash)
|
70
|
+
expect(user).to be_an_instance_of(described_class)
|
71
|
+
expect(user.uid).to eq("12345")
|
72
|
+
expect(user.anonymous_user_id).to eq("91f4d86cd48c6d0cf")
|
73
|
+
expect(user.name).to eq("Joe Smith")
|
74
|
+
expect(user.email).to eq("joe.smith@example.com")
|
75
|
+
expect(user).not_to be_disabled
|
76
|
+
expect(user.permissions).to eq(%w[signin])
|
77
|
+
expect(user.organisation_slug).to eq("cabinet-office")
|
78
|
+
expect(user.organisation_content_id).to eq("91e57ad9-29a3-4f94-9ab4-5e9ae6d13588")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
67
83
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
84
|
+
def with_anonymous_user_id_secret(value, &block)
|
85
|
+
if defined?(ClimateControl)
|
86
|
+
ClimateControl.modify(ANONYMOUS_USER_ID_SECRET: value, &block)
|
87
|
+
else
|
88
|
+
# If ClimateControl isn't available, we fall back to a simpler way of setting / resetting the environment
|
89
|
+
# variable. This doesn't account for tests running in parallel though.
|
90
|
+
begin
|
91
|
+
ENV["ANONYMOUS_USER_ID_SECRET"] = value
|
92
|
+
block.call
|
93
|
+
ensure
|
94
|
+
ENV.delete "ANONYMOUS_USER_ID_SECRET"
|
95
|
+
end
|
96
|
+
end
|
77
97
|
end
|
78
98
|
end
|
data/lib/gds-sso/user.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "active_support/concern"
|
2
|
+
require "json"
|
2
3
|
|
3
4
|
module GDS
|
4
5
|
module SSO
|
@@ -39,6 +40,13 @@ module GDS
|
|
39
40
|
update_attribute(:remotely_signed_out, true)
|
40
41
|
end
|
41
42
|
|
43
|
+
def anonymous_user_id
|
44
|
+
secret = ENV["ANONYMOUS_USER_ID_SECRET"]
|
45
|
+
return if secret.nil?
|
46
|
+
|
47
|
+
@anonymous_user_id ||= Digest::SHA2.hexdigest(JSON.dump([uid, secret]))[..16]
|
48
|
+
end
|
49
|
+
|
42
50
|
module ClassMethods
|
43
51
|
def find_for_gds_oauth(auth_hash)
|
44
52
|
user_params = GDS::SSO::User.user_params_from_auth_hash(auth_hash.to_hash)
|
data/lib/gds-sso/version.rb
CHANGED
data/spec/unit/user_spec.rb
CHANGED
@@ -30,6 +30,26 @@ describe GDS::SSO::User do
|
|
30
30
|
expect(GDS::SSO::User.user_params_from_auth_hash(@auth_hash)).to eq(expected)
|
31
31
|
end
|
32
32
|
|
33
|
+
describe "#anonymous_user_id" do
|
34
|
+
it "should be nil if ANONYMOUS_USER_ID_SECRET is unset" do
|
35
|
+
ClimateControl.modify ANONYMOUS_USER_ID_SECRET: nil do
|
36
|
+
expect(TestUser.new.anonymous_user_id).to be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be computed based on the uid and ANONYMOUS_USER_ID_SECRET" do
|
41
|
+
ClimateControl.modify ANONYMOUS_USER_ID_SECRET: "some-anonymous-user-id-secret" do
|
42
|
+
expect("8724f603978a3adc0").to eq(TestUser.new(uid: "some-user-id").anonymous_user_id)
|
43
|
+
expect("69d0cf995988be2e1").to eq(TestUser.new(uid: "some-other-user-id").anonymous_user_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
ClimateControl.modify ANONYMOUS_USER_ID_SECRET: "other-anonymous-user-id-secret" do
|
47
|
+
expect("297069f42a9251c64").to eq(TestUser.new(uid: "some-user-id").anonymous_user_id)
|
48
|
+
expect("4a3c66e26f5ec4229").to eq(TestUser.new(uid: "other-user-id").anonymous_user_id)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
33
53
|
context "making sure that the lint spec is valid" do
|
34
54
|
let(:described_class) { TestUser }
|
35
55
|
it_behaves_like "a gds-sso user class"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-sso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 22.
|
4
|
+
version: 22.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
@@ -183,14 +183,14 @@ dependencies:
|
|
183
183
|
requirements:
|
184
184
|
- - '='
|
185
185
|
- !ruby/object:Gem::Version
|
186
|
-
version: 5.1.
|
186
|
+
version: 5.1.20
|
187
187
|
type: :development
|
188
188
|
prerelease: false
|
189
189
|
version_requirements: !ruby/object:Gem::Requirement
|
190
190
|
requirements:
|
191
191
|
- - '='
|
192
192
|
- !ruby/object:Gem::Version
|
193
|
-
version: 5.1.
|
193
|
+
version: 5.1.20
|
194
194
|
- !ruby/object:Gem::Dependency
|
195
195
|
name: sqlite3
|
196
196
|
requirement: !ruby/object:Gem::Requirement
|