spec/unit/session_serialisation_spec.rb in gds-sso-9.2.5 vs spec/unit/session_serialisation_spec.rb in gds-sso-9.2.6
- old
+ new
@@ -16,16 +16,16 @@
after :each do
GDS::SSO::Config.user_model = @old_user_model
end
describe "serializing a user" do
-
- it "should return the uid and a timestamp" do
+ it "should return the uid and an ISO 8601 string timestamp" do
Timecop.freeze
result = @serializer.serialize(@user)
- expect(result).to eq([1234, Time.now.utc])
+ expect(result).to eq([1234, Time.now.utc.iso8601])
+ expect(result.last).to be_a(String)
end
it "should return nil if the user has no uid" do
@user.stub(:uid).and_return(nil)
result = @serializer.serialize(@user)
@@ -33,18 +33,26 @@
expect(result).to be_nil
end
end
describe "deserialize a user" do
- it "should return the user if the timestamp is current" do
+ it "should return the user if the timestamp is current and a Time" do
expect(User).to receive(:where).with(:uid => 1234, :remotely_signed_out => false).and_return(double(:first => :a_user))
result = @serializer.deserialize [1234, Time.now.utc - GDS::SSO::Config.auth_valid_for + 3600]
expect(result).to equal(:a_user)
end
+ it "should return the user if the timestamp is current and is an ISO 8601 string" do
+ expect(User).to receive(:where).with(:uid => 1234, :remotely_signed_out => false).and_return(double(:first => :a_user))
+
+ result = @serializer.deserialize [1234, (Time.now.utc - GDS::SSO::Config.auth_valid_for + 3600).iso8601]
+
+ expect(result).to equal(:a_user)
+ end
+
it "should return nil if the timestamp is out of date" do
expect(User).not_to receive(:where)
result = @serializer.deserialize [1234, Time.now.utc - GDS::SSO::Config.auth_valid_for - 3600]
@@ -53,9 +61,17 @@
it "should return nil for a user without a timestamp" do
expect(User).not_to receive(:where)
result = @serializer.deserialize 1234
+
+ expect(result).to be_nil
+ end
+
+ it "should return nil for a user with a badly formatted timestamp" do
+ expect(User).not_to receive(:where)
+
+ result = @serializer.deserialize [1234, 'this is not a timestamp']
expect(result).to be_nil
end
end
end