discourse/spec/lib/secure_session_spec.rb
Jarek Radosz 694b5f108b
DEV: Fix various rubocop lints (#24749)
These (21 + 3 from previous PRs) are soon to be enabled in rubocop-discourse:

Capybara/VisibilityMatcher
Lint/DeprecatedOpenSSLConstant
Lint/DisjunctiveAssignmentInConstructor
Lint/EmptyConditionalBody
Lint/EmptyEnsure
Lint/LiteralInInterpolation
Lint/NonLocalExitFromIterator
Lint/ParenthesesAsGroupedExpression
Lint/RedundantCopDisableDirective
Lint/RedundantRequireStatement
Lint/RedundantSafeNavigation
Lint/RedundantStringCoercion
Lint/RedundantWithIndex
Lint/RedundantWithObject
Lint/SafeNavigationChain
Lint/SafeNavigationConsistency
Lint/SelfAssignment
Lint/UnreachableCode
Lint/UselessMethodDefinition
Lint/Void

Previous PRs:
Lint/ShadowedArgument
Lint/DuplicateMethods
Lint/BooleanSymbol
RSpec/SpecFilePathSuffix
2023-12-06 23:25:00 +01:00

28 lines
635 B
Ruby

# frozen_string_literal: true
RSpec.describe SecureSession do
it "operates correctly" do
s = SecureSession.new("abc")
s["hello"] = "world"
s["foo"] = "bar"
expect(s["hello"]).to eq("world")
expect(s["foo"]).to eq("bar")
s["hello"] = nil
expect(s["hello"]).to eq(nil)
end
it "can override expiry" do
s = SecureSession.new("abc")
key = SecureRandom.hex
s.set(key, "test2", expires: 5.minutes)
expect(s.ttl(key)).to be_within(1.second).of(5.minutes)
key = SecureRandom.hex
s.set(key, "test2")
expect(s.ttl(key)).to be_within(1.second).of(SecureSession.expiry)
end
end