spec/lib/api_spec.rb in conjur-api-4.25.0 vs spec/lib/api_spec.rb in conjur-api-4.25.1
- old
+ new
@@ -252,18 +252,41 @@
expect(api.instance_variable_get("@token")).to eq(nil)
expect(api.token).to eq(token)
expect(api.credentials).to eq({ headers: { authorization: "Token token=\"#{Base64.strict_encode64(token.to_json)}\"" }, username: login })
end
- it "fetches a new token if old" do
- allow(Conjur::API).to receive(:authenticate).with(login, api_key).and_return token
- expect(Time.parse(api.token['timestamp'])).to be_within(5.seconds).of(Time.now)
+ context "after expiration" do
- time_travel 6.minutes
- new_token = token.merge "timestamp" => Time.now.to_s
+ shared_examples "it gets a new token" do
+ it 'by refreshing' do
+ allow(Conjur::API).to receive(:authenticate).with(login, api_key).and_return token
+ expect(Time.parse(api.token['timestamp'])).to be_within(5.seconds).of(Time.now)
+
+ time_travel 6.minutes
+ new_token = token.merge "timestamp" => Time.now.to_s
+
+ expect(Conjur::API).to receive(:authenticate).with(login, api_key).and_return new_token
+ expect(api.token).to eq(new_token)
+ end
+ end
- expect(Conjur::API).to receive(:authenticate).with(login, api_key).and_return new_token
- expect(api.token).to eq(new_token)
+ it_should_behave_like "it gets a new token"
+
+ context "with elevated privilege" do
+ subject(:api) { Conjur::API.new_from_key(*api_args).with_privilege('reveal') }
+ it_should_behave_like "it gets a new token"
+ end
+
+ context "with audit roles" do
+ subject(:api) { Conjur::API.new_from_key(*api_args).with_audit_roles('account:host:host1') }
+ it_should_behave_like "it gets a new token"
+ end
+
+ context "with audit resources" do
+ subject(:api) { Conjur::API.new_from_key(*api_args).with_audit_resources('account:webservice:service1') }
+ it_should_behave_like "it gets a new token"
+ end
+
end
end
context 'with no API key available', logged_in: true do
it "returns the token used to create it" do