Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ jobs:
- uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 9.0.0-SNAPSHOT
security-enabled: false
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -40,4 +39,4 @@ jobs:
- name: elasticsearch
run: cd elasticsearch && bundle exec rake test:all
- name: elasticsearch-api
run: rake es:download_artifacts[9.0.0-SNAPSHOT] && cd elasticsearch-api && bundle exec rake test:spec test:platinum:unit
run: rake es:download_artifacts[9.0.0-SNAPSHOT] && cd elasticsearch-api && bundle exec rake test:all
3 changes: 1 addition & 2 deletions .github/workflows/otel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ jobs:
- uses: elastic/elastic-github-actions/elasticsearch@master
with:
stack-version: 9.0.0-SNAPSHOT
security-enabled: false
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
Expand All @@ -42,4 +41,4 @@ jobs:
- name: elasticsearch
run: cd elasticsearch && bundle exec rake test:all
- name: elasticsearch-api
run: rake es:download_artifacts[9.0.0-SNAPSHOT] && cd elasticsearch-api && bundle exec rake test:spec test:platinum:unit
run: rake es:download_artifacts[9.0.0-SNAPSHOT] && cd elasticsearch-api && bundle exec rake test:all
2 changes: 1 addition & 1 deletion CHANGELOG-9.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ The gem migrated away from the Elasticsearch REST API tests and test runner in C
#### Rake tasks

* Some old rake tasks that were not being used have been removed. The rest were streamlined, the `es` namespace has been streamlined to make it easier to run Elasticsearch with Docker during development. The `docker` namespace was merged into `es`.
* Elasticsearch's REST API Spec tests can still be ran with `rake test:es_free` and `rake test:es_platinum`.
* Elasticsearch's REST API Spec tests can still be ran with `rake test:deprecated:rest_api` and setting the corresponding value for the environment variable `TEST_SUITE` ('platinum' or 'free').
52 changes: 20 additions & 32 deletions elasticsearch-api/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@ namespace :test do
end

desc 'Run unit tests'
task unit: :spec
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/elasticsearch/api/**/*_spec.rb'
t.exclude_pattern = 'spec/platinum/**/*_spec.rb'
end

desc 'Run Elasticsearch test suite free tests.'
RSpec::Core::RakeTask.new(:rest_api) do |t|
test_dir = Rake.application.original_dir
t.pattern = "#{test_dir}/spec/rest_api/rest_api_yaml_spec.rb"
task :unit
RSpec::Core::RakeTask.new(:unit) do |t|
t.pattern = 'spec/unit/**/*_spec.rb'
t.ruby_opts = '-W0'
end

desc 'Run unit and integration tests'
Expand All @@ -55,29 +49,23 @@ namespace :test do
ruby './spec/yaml-test-runner/run.rb'
end

namespace :platinum do
desc 'Run Platinum Rest API Spec tests'
RSpec::Core::RakeTask.new(:api) do
ENV['TEST_SUITE'] = 'platinum'
Rake::Task['test:rest_api'].invoke
end

desc 'Run Platinum Unit tests - DEPRECATED: Will be migrated to RSpec'
Rake::TestTask.new(:unit) do |test|
test.libs << 'spec/platinum/unit'
test.test_files = FileList['spec/platinum/unit/**/*_test.rb']
test.verbose = false
test.warning = false
end
desc 'Run Integration tests'
RSpec::Core::RakeTask.new(:integration) do |t|
t.pattern = 'spec/integration/**/*_spec.rb'
t.ruby_opts = '-W0'
end

desc 'Run Platinum Integration Specs'
RSpec::Core::RakeTask.new(:integration) do |t|
t.pattern = if ENV['TEST_SUITE'] == 'platinum'
'spec/platinum/integration/**/*_spec.rb'
else
'spec/free/integration/**/*_spec.rb'
end
t.ruby_opts = '-W0'
# This is the task to run the Elasticsearch REST tests which we stopped using for 9.x.
# Use the environment variable TEST_SUITE to choose between 'free' and 'platinum' tests. For
# platinum, the test cluster needs to have the license activated and run with security enabled.
# For 'free', security must be disabled in the test cluster.
#
namespace :deprecated do
# TODO: TEST_SUITE
desc 'Run Elasticsearch test suite free tests.'
RSpec::Core::RakeTask.new(:rest_api) do |t|
test_dir = Rake.application.original_dir
t.pattern = "#{test_dir}/spec/rest_api/rest_api_yaml_spec.rb"
end
end
end
Expand Down
5 changes: 0 additions & 5 deletions elasticsearch-api/elasticsearch-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ Gem::Specification.new do |s|
s.add_development_dependency 'bundler'
s.add_development_dependency 'elasticsearch'
s.add_development_dependency 'elasticsearch-test-runner' unless defined?(JRUBY_VERSION) && JRUBY_VERSION <= '9.4'
s.add_development_dependency 'minitest'
s.add_development_dependency 'minitest-reporters', '>= 1.6'
s.add_development_dependency 'mocha'
s.add_development_dependency 'pry'
s.add_development_dependency 'rake'
s.add_development_dependency 'shoulda-context'
s.add_development_dependency 'yard'

# Gems for testing integrations
Expand All @@ -68,7 +64,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
s.add_development_dependency 'simplecov'
s.add_development_dependency 'test-unit', '~> 2'
s.description = <<-DESC.gsub(/^ /, '')
Ruby API for Elasticsearch. See the `elasticsearch` gem for full integration.
DESC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
Expand All @@ -16,21 +18,21 @@
# under the License.

require 'base64'
require_relative '../platinum_helper'
require_relative './spec_helper'

describe 'API keys' do
before do
ADMIN_CLIENT.security.put_user(
CLIENT.security.put_user(
username: client_username,
body: { password: 'test-password', roles: ['superuser'] }
)
end

after do
ADMIN_CLIENT.security.delete_user(username: client_username)
CLIENT.security.delete_user(username: client_username)
end

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

let(:client) do
Expand All @@ -41,71 +43,71 @@
end

it 'queries API keys' do
key_name_1 = "query-key-1-#{Time.new.to_i}"
key_name1 = "query-key-1-#{Time.new.to_i}"
response = client.security.create_api_key(
body: {
name: key_name_1,
name: key_name1,
role_descriptors: {},
expiration: "1d",
metadata: { search: "this" }
expiration: '1d',
metadata: { search: 'this' }
}
)
expect(response['name']).to eq key_name_1
expect(response['name']).to eq key_name1
expect(response['api_key']).not_to be nil
api_key_id_1 = response['id']
api_key_id1 = response['id']

key_name_2 = "query-key-2-#{Time.new.to_i}"
key_name2 = "query-key-2-#{Time.new.to_i}"
response = client.security.create_api_key(
body: {
name: key_name_2,
expiration: "2d",
role_descriptors: { "role-a" => { "cluster": [ "monitor"] } },
name: key_name2,
expiration: '2d',
role_descriptors: { 'role-a' => { "cluster": ['monitor'] } },
metadata: { search: false }
}
)
expect(response['name']).to eq key_name_2
expect(response['name']).to eq key_name2
expect(response['api_key']).not_to be nil
api_key_id_2 = response['id']
api_key_id2 = response['id']

key_name_3 = "query-key-3#{Time.new.to_i}"
key_name3 = "query-key-3#{Time.new.to_i}"
response = client.security.create_api_key(
body: {
name: key_name_3,
expiration: "3d",
name: key_name3,
expiration: '3d'
}
)
expect(response['name']).to eq key_name_3
expect(response['name']).to eq key_name3
expect(response['api_key']).not_to be nil
api_key_id_3 = response['id']
api_key_id3 = response['id']

response = client.security.authenticate
owner_name = response['username']
response['username']

response = client.security.query_api_keys(
body: {
query: { wildcard: { name: key_name_1 }}
query: { wildcard: { name: key_name1 } }
}
)
expect(response['total']).to eq 1
expect(response['count']).to eq 1
expect(response['api_keys'].first['id']).to eq api_key_id_1
expect(response['api_keys'].first['id']).to eq api_key_id1

response = client.security.query_api_keys(
body: {
query: { wildcard: { name: key_name_2 }}
query: { wildcard: { name: key_name2 } }
}
)
expect(response['total']).to eq 1
expect(response['count']).to eq 1
expect(response['api_keys'].first['id']).to eq api_key_id_2
expect(response['api_keys'].first['id']).to eq api_key_id2

response = client.security.query_api_keys(
body: {
query: { wildcard: { name: key_name_3 }}
query: { wildcard: { name: key_name3 } }
}
)
expect(response['total']).to eq 1
expect(response['count']).to eq 1
expect(response['api_keys'].first['id']).to eq api_key_id_3
expect(response['api_keys'].first['id']).to eq api_key_id3
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
Expand All @@ -15,12 +17,20 @@
# specific language governing permissions and limitations
# under the License.

require_relative '../platinum_helper'
require_relative './spec_helper'

describe 'Health basic test' do
it 'performs the request' do
response = CLIENT.health_report
expect(response.status).to eq 200
expect(response['cluster_name']).not_to be_nil
expect(response.dig('indicators', 'master_is_stable', 'symptom')).to eq 'The cluster has a stable master node'
expect(response.dig('indicators', 'master_is_stable', 'status')).to eq 'green'
end

describe 'Health API' do
context 'Usage stats on the health API' do
before do
ADMIN_CLIENT.indices.create(
CLIENT.indices.create(
index: 'red_index',
body: {
settings: {
Expand All @@ -33,13 +43,13 @@
end

after do
ADMIN_CLIENT.indices.delete(index: 'red_index')
CLIENT.indices.delete(index: 'red_index')
end

it 'responds with health report' do
expect(ADMIN_CLIENT.health_report.status).to eq 200
expect(ADMIN_CLIENT.health_report(feature: 'disk').status).to eq 200
response = ADMIN_CLIENT.xpack.usage
expect(CLIENT.health_report.status).to eq 200
expect(CLIENT.health_report(feature: 'disk').status).to eq 200
response = CLIENT.xpack.usage
expect(response['health_api']['available']).to eq true
expect(response['health_api']['enabled']).to eq true
expect(response['health_api']['invocations']['total']).to be >= 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
Expand All @@ -14,13 +16,11 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

require 'openssl'
require 'elasticsearch'

CERTS_PATH = File.expand_path('./../.buildkite/certs')

host = ENV['TEST_ES_SERVER'] || 'https://localhost:9200'
CERTS_PATH = File.expand_path('./../../../.buildkite/certs', __dir__)
host = ENV['TEST_ES_SERVER'] || 'http://localhost:9200'
raise URI::InvalidURIError unless host =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/

password = ENV['ELASTIC_PASSWORD'] || 'changeme'
Expand All @@ -31,12 +31,11 @@
key = OpenSSL::PKey::RSA.new(raw_key)
ca_file = File.expand_path("#{CERTS_PATH}/ca.crt")
TRANSPORT_OPTIONS = { ssl: { verify: false, client_cert: certificate, client_key: key, ca_file: ca_file } }
HOST = "https://elastic:#{password}@#{HOST_URI.host}:#{HOST_URI.port}".freeze

ADMIN_CLIENT = Elasticsearch::Client.new(host: HOST, transport_options: TRANSPORT_OPTIONS)
HOST = "https://elastic:#{password}@#{HOST_URI.host}:#{HOST_URI.port}"
CLIENT = Elasticsearch::Client.new(host: HOST, transport_options: TRANSPORT_OPTIONS)

RSpec.configure do |config|
config.add_formatter('documentation')
config.add_formatter('RSpec::Core::Formatters::HtmlFormatter', "tmp/platinum-#{ENV['RUBY_VERSION']}-manual-integration.html")
config.add_formatter('RSpec::Core::Formatters::HtmlFormatter', "tmp/#{ENV['RUBY_VERSION']}-manual-integration.html")
config.color_mode = :on
end

This file was deleted.

Loading