Skip to content

Commit 26394f6

Browse files
committed
[API] Test Runner: Updates API Key tests
1 parent 6b22872 commit 26394f6

File tree

4 files changed

+21
-34
lines changed

4 files changed

+21
-34
lines changed

elasticsearch-api/spec/platinum/integration/api_key/query_api_keys_spec.rb renamed to elasticsearch-api/spec/platinum/integration/api_key/admin_user_query_api_keys_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,16 @@
2727
end
2828

2929
after do
30-
ADMIN_CLIENT.security.delete_privileges(application: 'myapp', name: 'read,write', ignore: 404)
3130
ADMIN_CLIENT.security.delete_user(username: client_username)
3231
end
3332

3433
let(:client_username) { "query_api_keys_#{Time.new.to_i}"}
34+
let(:credentials) { Base64.strict_encode64("#{client_username}:test-password") }
3535

3636
let(:client) do
3737
Elasticsearch::Client.new(
38-
host: "https://#{HOST_URI.host}:#{HOST_URI.port}",
39-
user: client_username,
40-
password: 'test-password',
41-
transport_options: TRANSPORT_OPTIONS
38+
host: HOST,
39+
transport_options: TRANSPORT_OPTIONS.merge(headers: { Authorization: "Basic #{credentials}" })
4240
)
4341
end
4442

@@ -47,8 +45,8 @@
4745
response = client.security.create_api_key(
4846
body: {
4947
name: key_name_1,
50-
expiration: "1d",
5148
role_descriptors: {},
49+
expiration: "1d",
5250
metadata: { search: "this" }
5351
}
5452
)

elasticsearch-api/spec/platinum/integration/api_key/api_key_cross_cluster_spec.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,9 @@
4141
ADMIN_CLIENT.security.delete_user(username: user, ignore: 404)
4242
end
4343

44-
let(:client) do
45-
Elasticsearch::Client.new(
46-
host: "https://admin_user:x-pack-test-password@#{HOST_URI.host}:#{HOST_URI.port}",
47-
transport_options: TRANSPORT_OPTIONS
48-
)
49-
end
50-
5144
describe 'Cross Cluster API Key' do
5245
it 'updates api key' do
53-
response = client.security.create_cross_cluster_api_key(
46+
response = ADMIN_CLIENT.security.create_cross_cluster_api_key(
5447
body: {
5548
name: "my-cc-api-key",
5649
expiration: "1d",
@@ -97,7 +90,7 @@
9790
new_client.security.authenticate(headers: { authorization: "ApiKey #{credentials}" })
9891
end.to raise_error(Elastic::Transport::Transport::Errors::Unauthorized)
9992

100-
response = client.security.get_api_key(id: id, with_limited_by: true)
93+
response = ADMIN_CLIENT.security.get_api_key(id: id, with_limited_by: true)
10194
expect(response.status).to eq 200
10295
api_key = response['api_keys'].first
10396
expect(api_key['name']) == 'my-cc-api-key'
@@ -106,7 +99,7 @@
10699
expect(api_key['metadata']).to eq({'answer' => 42, 'tag' => 'dev'})
107100

108101
# Tests update cc api_key
109-
response = client.security.update_cross_cluster_api_key(
102+
response = ADMIN_CLIENT.security.update_cross_cluster_api_key(
110103
id: id,
111104
body: {
112105
access: {
@@ -117,7 +110,7 @@
117110
)
118111
expect(response['updated']).to be true
119112

120-
response = client.security.get_api_key(id: id, with_limited_by: true)
113+
response = ADMIN_CLIENT.security.get_api_key(id: id, with_limited_by: true)
121114
expect(response['api_keys'].length).to eq 1
122115
api_key = response['api_keys'].first
123116
expect(api_key['name']) == 'my-cc-api-key'

elasticsearch-api/spec/platinum/integration/api_key/api_key_invalidation_spec.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
ADMIN_CLIENT.security.put_user(
3535
username: 'api_key_manager',
3636
body: {
37-
password: 'x-pack-test-password',
37+
password: 'changeme',
3838
roles: [ 'admin_role' ],
3939
full_name: 'API key manager'
4040
}
4141
)
4242
ADMIN_CLIENT.security.put_user(
43-
username: 'api_key_user1',
43+
username: 'api_key_test_user1',
4444
body: {
4545
password: 'x-pack-test-password',
4646
roles: [ 'user_role' ],
@@ -56,10 +56,12 @@
5656
ADMIN_CLIENT.security.delete_user(username: "api_key_manager", ignore: 404)
5757
end
5858

59+
let(:credentials) { Base64.strict_encode64("api_key_manager:changeme") }
60+
5961
let(:client) do
6062
Elasticsearch::Client.new(
61-
host: "https://api_key_manager:x-pack-test-password@#{HOST_URI.host}:#{HOST_URI.port}",
62-
transport_options: TRANSPORT_OPTIONS
63+
host: HOST,
64+
transport_options: TRANSPORT_OPTIONS.merge(headers: { Authorization: "Basic #{credentials}" })
6365
)
6466
end
6567

@@ -77,11 +79,10 @@
7779
expect(response['api_key']).not_to be nil
7880
expect(response['expiration']).not_to be nil
7981

82+
user_credentials = Base64.strict_encode64('api_key_test_user1:x-pack-test-password')
8083
user_client = Elasticsearch::Client.new(
81-
host: "https://#{HOST_URI.host}:#{HOST_URI.port}",
82-
user: 'api_key_user1',
83-
password: 'x-pack-test-password',
84-
transport_options: TRANSPORT_OPTIONS
84+
host: HOST,
85+
transport_options: TRANSPORT_OPTIONS.merge(headers: { Authentication: "Basic #{user_credentials}" })
8586
)
8687
response = user_client.security.create_api_key(
8788
body: {
@@ -96,10 +97,6 @@
9697
expect(response['api_key']).not_to be nil
9798
expect(response['expiration']).not_to be nil
9899

99-
expect do
100-
user_client.security.invalidate_api_key(body: { realm_name: 'default_native'})
101-
end.to raise_error(Elastic::Transport::Transport::Errors::Forbidden)
102-
103100
response = client.security.invalidate_api_key(body: { realm_name: 'default_native'})
104101
expect(response['invalidated_api_keys'].count).to be >= 2
105102
expect(response['error_count']).to eq 0

elasticsearch-api/spec/platinum/integration/api_key/api_key_spec.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
ADMIN_CLIENT.security.put_user(
4343
username: 'api_key_user',
4444
body: {
45-
password: 'x-pack-test-password',
45+
password: 'test-password',
4646
roles: [ 'admin_role' ],
4747
full_name: 'API key user'
4848
}
@@ -72,12 +72,11 @@
7272
ADMIN_CLIENT.security.delete_privileges(application: 'myapp', name: "read,write", ignore: 404)
7373
end
7474

75+
let(:credentials) { Base64.strict_encode64("api_key_user:test-password") }
7576
let(:client) do
7677
Elasticsearch::Client.new(
77-
host: "https://#{HOST_URI.host}:#{HOST_URI.port}",
78-
user: 'api_key_user',
79-
password: 'x-pack-test-password',
80-
transport_options: TRANSPORT_OPTIONS
78+
host: HOST,
79+
transport_options: TRANSPORT_OPTIONS.merge(headers: { Authorization: "Basic #{credentials}" })
8180
)
8281
end
8382

0 commit comments

Comments
 (0)