Commit 8deb7069 authored by Robert Speicher's avatar Robert Speicher

Merge branch...

Merge branch '227033-follow-up-from-highlight-expired-ssh-or-pat-credentials-in-the-credential-inventory' into 'master'

Follow-up: Restructure SSH and PAT credential inventory tests

Closes #227033

See merge request gitlab-org/gitlab!36079
parents 18d573bf ef18b18d
......@@ -2,46 +2,6 @@
require 'spec_helper'
RSpec.shared_examples 'credentials inventory expiry date' do
it 'shows the expiry date' do
visit credentials_path
expect(first_row.text).to include(expiry_date)
end
end
RSpec.shared_examples 'credentials inventory expiry date before' do
before do
travel_to(view_at_date)
end
after do
travel_back
end
it 'shows the expiry without any warnings' do
visit credentials_path
expect(first_row).not_to have_selector('[data-testid="expiry-date-icon"]')
end
end
RSpec.shared_examples 'credentials inventory expiry date close or past' do
before do
travel_to(view_at_date)
end
after do
travel_back
end
it 'adds a warning to the expiry date' do
visit credentials_path
expect(first_row.find('[data-testid="expiry-date-icon"]').find('svg').native.inner_html).to match(/<use xlink:href=".+?icons-.+?##{expected_icon}">/)
end
end
RSpec.shared_examples_for 'credentials inventory personal access tokens' do |group_managed_account: false|
let_it_be(:user) { group_managed_account ? managed_user : create(:user, name: 'David') }
......@@ -58,7 +18,7 @@ RSpec.shared_examples_for 'credentials inventory personal access tokens' do |gro
visit credentials_path
end
it 'shows the details with no revoked date', :aggregate_failures do
it 'shows the details', :aggregate_failures do
expect(first_row.text).to include('David')
expect(first_row.text).to include('api')
expect(first_row.text).to include('2019-12-10')
......@@ -78,27 +38,16 @@ RSpec.shared_examples_for 'credentials inventory personal access tokens' do |gro
expires_at: expiry_date)
end
context 'and is not expired' do
let(:view_at_date) { 20.days.ago }
it_behaves_like 'credentials inventory expiry date'
it_behaves_like 'credentials inventory expiry date before'
before do
visit credentials_path
end
context 'and is near expiry' do
let(:expected_icon) { 'warning' }
let(:view_at_date) { 1.day.ago }
it_behaves_like 'credentials inventory expiry date'
it_behaves_like 'credentials inventory expiry date close or past'
it 'shows the details with an expiry date' do
expect(first_row.text).to include(expiry_date)
end
context 'and is expired' do
let(:expected_icon) { 'error' }
let(:view_at_date) { 2.days.since }
it_behaves_like 'credentials inventory expiry date'
it_behaves_like 'credentials inventory expiry date close or past'
it 'has an expiry icon' do
expect(first_row).to have_selector('[data-testid="expiry-date-icon"]')
end
end
......@@ -117,9 +66,6 @@ RSpec.shared_examples_for 'credentials inventory personal access tokens' do |gro
end
it 'shows the details with a revoked date', :aggregate_failures do
expect(first_row.text).to include('David')
expect(first_row.text).to include('api')
expect(first_row.text).to include('2019-12-10')
expect(first_row.text).to include('2020-06-22')
end
end
......@@ -141,7 +87,7 @@ RSpec.shared_examples_for 'credentials inventory SSH keys' do |group_managed_acc
visit credentials_path
end
it 'shows the details with no expiry', :aggregate_failures do
it 'shows the details', :aggregate_failures do
expect(first_row.text).to include('David')
expect(first_row.text).to include('2019-12-09')
expect(first_row.text).to include('2019-12-10')
......@@ -160,27 +106,16 @@ RSpec.shared_examples_for 'credentials inventory SSH keys' do |group_managed_acc
expires_at: expiry_date)
end
context 'and is not expired' do
let(:view_at_date) { 20.days.ago }
it_behaves_like 'credentials inventory expiry date'
it_behaves_like 'credentials inventory expiry date before'
before do
visit credentials_path
end
context 'and is near expiry' do
let(:expected_icon) { 'warning' }
let(:view_at_date) { 1.day.ago }
it_behaves_like 'credentials inventory expiry date'
it_behaves_like 'credentials inventory expiry date close or past'
it 'shows the details with an expiry date' do
expect(first_row.text).to include(expiry_date)
end
context 'and is expired' do
let(:expected_icon) { 'error' }
let(:view_at_date) { 2.days.since }
it_behaves_like 'credentials inventory expiry date'
it_behaves_like 'credentials inventory expiry date close or past'
it 'has an expiry icon' do
expect(first_row).to have_selector('[data-testid="expiry-date-icon"]')
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe('shared/credentials_inventory/_expiry_date.html.haml') do
let_it_be(:user) { create(:user) }
before do
render 'shared/credentials_inventory/expiry_date', credential: credential
end
context 'when a non-expirable credential is used' do
let_it_be(:credential) { create(:deploy_key, user: user)}
it 'shows "Never" if expires? method does not exist' do
expect(rendered).to have_text('Never')
end
end
context 'when an expirable credential is used' do
let_it_be(:credential) { create(:personal_access_token, user: user, expires_at: nil)}
it 'shows "Never" when not expirable' do
expect(rendered).to have_text('Never')
end
context 'and is not expired' do
let_it_be(:expiry_date) { 20.days.since.to_date.to_s }
let_it_be(:credential) { create(:personal_key, user: user, expires_at: expiry_date)}
it 'shows the correct date' do
expect(rendered).to have_text(expiry_date)
end
it 'does not have an expiry icon' do
expect(rendered).not_to have_selector('[data-testid="expiry-date-icon"]')
end
end
context 'and is near expiry' do
let_it_be(:expiry_date) { 1.day.since.to_date.to_s }
let_it_be(:credential) { create(:personal_access_token, user: user, expires_at: expiry_date)}
it 'shows the correct date' do
expect(rendered).to have_text(expiry_date)
end
it 'has an icon' do
expect(rendered).to match(/<use xlink:href=".+?icons-.+?#warning">/)
end
end
context 'and has expired' do
let_it_be(:expiry_date) { 2.days.ago.to_date.to_s }
let_it_be(:credential) { create(:personal_access_token, user: user, expires_at: expiry_date)}
it 'shows the correct date' do
expect(rendered).to have_text(expiry_date)
end
it 'has an icon' do
expect(rendered).to match(/<use xlink:href=".+?icons-.+?#error">/)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe('shared/credentials_inventory/personal_access_tokens/_personal_access_token.html.haml') do
let_it_be(:user) { create(:user) }
let_it_be(:expiry_date) { 20.days.since }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user, expires_at: expiry_date)}
before do
allow(view).to receive(:user_detail_path).and_return('abcd')
render 'shared/credentials_inventory/personal_access_tokens/personal_access_token', personal_access_token: personal_access_token
end
it 'shows the users name' do
expect(rendered).to have_text(user.name)
end
it 'shows the created on date' do
expect(rendered).to have_text(personal_access_token.created_at.to_date.to_s)
end
it 'shows the expiry date' do
expect(rendered).to have_text(personal_access_token.expires_at.to_date.to_s)
end
context 'revoked date' do
let_it_be(:updated_at_date) { 10.days.ago }
context 'when set' do
let_it_be(:personal_access_token) { create(:personal_access_token, user: user, updated_at: updated_at_date, revoked: true)}
it 'shows the last accessed on date' do
expect(rendered).to have_text(personal_access_token.updated_at.to_date.to_s)
end
end
context 'when not set' do
let_it_be(:personal_access_token) { create(:personal_access_token, user: user, updated_at: updated_at_date)}
it 'shows "Never" for the last accessed on date' do
expect(rendered).not_to have_text(updated_at_date.to_date.to_s)
end
end
end
context 'scopes' do
context 'when set' do
let_it_be(:scopes) { %w(api read_user read_api) }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user, scopes: scopes)}
it 'shows the scopes' do
expect(rendered).to have_text(personal_access_token.scopes.join(', '))
end
end
context 'when not set' do
let_it_be(:personal_access_token) { create(:personal_access_token, user: user)}
before do
# Turns out on creation of a PersonalAccessToken we set some default scopes and you can't pass `nil`
# This is forcing the scope to be `nil` even though it looks impossible to do, we have the logic in the view
personal_access_token.scopes = nil
render 'shared/credentials_inventory/personal_access_tokens/personal_access_token', personal_access_token: personal_access_token
end
it 'shows "No Scopes"' do
expect(rendered).to have_text('Scope No Scopes')
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe('shared/credentials_inventory/ssh_keys/_ssh_key.html.haml') do
let_it_be(:user) { create(:user) }
let_it_be(:expiry_date) { 20.days.since }
let_it_be(:ssh_key) { create(:personal_key, user: user, expires_at: expiry_date)}
before do
allow(view).to receive(:user_detail_path).and_return('abcd')
render 'shared/credentials_inventory/ssh_keys/ssh_key', ssh_key: ssh_key
end
it 'shows the users name' do
expect(rendered).to have_text(user.name)
end
it 'shows the created on date' do
expect(rendered).to have_text(ssh_key.created_at.to_date.to_s)
end
it 'shows the expiry date' do
expect(rendered).to have_text(ssh_key.expires_at.to_date.to_s)
end
context 'last accessed date' do
context 'when set' do
let_it_be(:last_used_date) { 10.days.ago }
let_it_be(:ssh_key) { create(:personal_key, user: user, last_used_at: last_used_date)}
it 'shows the last accessed on date' do
expect(rendered).to have_text(ssh_key.last_used_at.to_date.to_s)
end
end
context 'when not set' do
let_it_be(:ssh_key) { create(:personal_key, user: user)}
it 'shows "Never" for the last accessed on date' do
expect(rendered).to have_text('Last Accessed On Never')
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment