elastic-enterprise-search 0.3.1 → 7.10.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ci/.gitignore +1 -0
- data/.ci/Dockerfile +12 -0
- data/.ci/certs/README.md +50 -0
- data/.ci/certs/ca.crt +20 -0
- data/.ci/certs/ca.key +27 -0
- data/.ci/certs/testnode.crt +21 -0
- data/.ci/certs/testnode.key +27 -0
- data/.ci/certs/testnode_no_san.crt +19 -0
- data/.ci/certs/testnode_no_san.key +27 -0
- data/.ci/functions/cleanup.sh +67 -0
- data/.ci/functions/imports.sh +60 -0
- data/.ci/functions/wait-for-container.sh +36 -0
- data/.ci/jobs/defaults.yml +69 -0
- data/.ci/jobs/elastic+enterprise-search-ruby+master.yml +12 -0
- data/.ci/jobs/elastic+enterprise-search-ruby+pull-request.yml +19 -0
- data/.ci/run-elasticsearch.sh +127 -0
- data/.ci/run-enterprise-search.sh +70 -0
- data/.ci/run-local.sh +14 -0
- data/.ci/run-repository.sh +47 -0
- data/.ci/run-tests +29 -0
- data/.ci/test-matrix.yml +13 -0
- data/.github/workflows/rubocop.yml +15 -0
- data/.github/workflows/testing.yml +40 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +52 -0
- data/Gemfile +22 -1
- data/{LICENSE.txt → LICENSE} +33 -32
- data/README.md +201 -103
- data/Rakefile +71 -1
- data/elastic-enterprise-search.gemspec +47 -13
- data/lib/elastic-enterprise-search.rb +20 -1
- data/lib/elastic/.rubocop.yml +6 -0
- data/lib/elastic/app-search/api/add_meta_engine_source.rb +48 -0
- data/lib/elastic/app-search/api/api_logs.rb +63 -0
- data/lib/elastic/app-search/api/count_analytics.rb +50 -0
- data/lib/elastic/app-search/api/create_curation.rb +52 -0
- data/lib/elastic/app-search/api/create_engine.rb +51 -0
- data/lib/elastic/app-search/api/create_synonym_set.rb +50 -0
- data/lib/elastic/app-search/api/curation.rb +52 -0
- data/lib/elastic/app-search/api/delete_curation.rb +52 -0
- data/lib/elastic/app-search/api/delete_documents.rb +48 -0
- data/lib/elastic/app-search/api/delete_engine.rb +48 -0
- data/lib/elastic/app-search/api/delete_meta_engine_source.rb +48 -0
- data/lib/elastic/app-search/api/delete_synonym_set.rb +52 -0
- data/lib/elastic/app-search/api/documents.rb +48 -0
- data/lib/elastic/app-search/api/engine.rb +48 -0
- data/lib/elastic/app-search/api/index_documents.rb +48 -0
- data/lib/elastic/app-search/api/list_curations.rb +50 -0
- data/lib/elastic/app-search/api/list_documents.rb +50 -0
- data/lib/elastic/app-search/api/list_engines.rb +47 -0
- data/lib/elastic/app-search/api/list_synonym_sets.rb +50 -0
- data/lib/elastic/app-search/api/log_clickthrough.rb +54 -0
- data/lib/elastic/app-search/api/multi_search.rb +50 -0
- data/lib/elastic/app-search/api/put_curation.rb +56 -0
- data/lib/elastic/app-search/api/put_documents.rb +48 -0
- data/lib/elastic/app-search/api/put_schema.rb +48 -0
- data/lib/elastic/app-search/api/put_search_settings.rb +48 -0
- data/lib/elastic/app-search/api/put_synonym_set.rb +54 -0
- data/lib/elastic/app-search/api/query_suggestion.rb +52 -0
- data/lib/elastic/app-search/api/reset_search_settings.rb +48 -0
- data/lib/elastic/app-search/api/schema.rb +48 -0
- data/lib/elastic/app-search/api/search.rb +48 -0
- data/lib/elastic/app-search/api/search_settings.rb +48 -0
- data/lib/elastic/app-search/api/synonym_set.rb +52 -0
- data/lib/elastic/app-search/api/top_clicks_analytics.rb +52 -0
- data/lib/elastic/app-search/api/top_queries_analytics.rb +51 -0
- data/lib/elastic/app-search/app_search.rb +65 -0
- data/lib/elastic/enterprise-search/api/health.rb +38 -0
- data/lib/elastic/enterprise-search/api/put_read_only.rb +40 -0
- data/lib/elastic/enterprise-search/api/read_only.rb +38 -0
- data/lib/elastic/enterprise-search/api/stats.rb +41 -0
- data/lib/elastic/enterprise-search/api/version.rb +38 -0
- data/lib/elastic/enterprise-search/client.rb +79 -15
- data/lib/elastic/enterprise-search/configuration.rb +32 -16
- data/lib/elastic/enterprise-search/exceptions.rb +19 -0
- data/lib/elastic/enterprise-search/request.rb +46 -80
- data/lib/elastic/enterprise-search/utils.rb +29 -1
- data/lib/elastic/enterprise-search/version.rb +20 -1
- data/lib/elastic/enterprise_search.rb +38 -0
- data/lib/elastic/workplace-search/api/add_user_permissions.rb +53 -0
- data/lib/elastic/workplace-search/api/create_external_identity.rb +49 -0
- data/lib/elastic/workplace-search/api/delete_documents.rb +49 -0
- data/lib/elastic/workplace-search/api/delete_external_identity.rb +49 -0
- data/lib/elastic/workplace-search/api/external_identity.rb +49 -0
- data/lib/elastic/workplace-search/api/index_documents.rb +49 -0
- data/lib/elastic/workplace-search/api/list_external_identities.rb +47 -0
- data/lib/elastic/workplace-search/api/list_permissions.rb +47 -0
- data/lib/elastic/workplace-search/api/put_external_identity.rb +53 -0
- data/lib/elastic/workplace-search/api/put_user_permissions.rb +53 -0
- data/lib/elastic/workplace-search/api/remove_user_permissions.rb +53 -0
- data/lib/elastic/workplace-search/api/search.rb +42 -0
- data/lib/elastic/workplace-search/api/user_permissions.rb +49 -0
- data/lib/elastic/workplace-search/workplace_search.rb +59 -0
- data/lib/generator/documentation_helper.rb +94 -0
- data/lib/generator/endpoint_generator.rb +119 -0
- data/lib/generator/parameters_exceptions.rb +40 -0
- data/lib/generator/parameters_helper.rb +144 -0
- data/lib/generator/templates/_license.erb +16 -0
- data/lib/generator/templates/endpoint_template.erb +29 -0
- data/lib/generator/templates/spec_template.erb +1 -0
- data/lib/generator/utils.rb +70 -0
- data/spec/app-search/api_count_analytics_spec.rb +34 -0
- data/spec/app-search/api_documents_spec.rb +88 -0
- data/spec/app-search/api_engines_spec.rb +67 -0
- data/spec/app-search/api_logs_spec.rb +36 -0
- data/spec/app-search/api_schema_spec.rb +34 -0
- data/spec/app-search/api_search_and_multi_search_spec.rb +48 -0
- data/spec/app-search/api_spec_helper.rb +14 -0
- data/spec/app-search/api_top_clicks_analytics_spec.rb +44 -0
- data/spec/app-search/api_top_queries_analytics_spec.rb +34 -0
- data/spec/app-search/client_spec.rb +68 -0
- data/spec/enterprise-search/client_spec.rb +96 -0
- data/spec/enterprise-search/request_spec.rb +114 -0
- data/spec/fixtures/vcr/add_user_permissions.yml +18 -22
- data/spec/fixtures/vcr/app_search/api_logs.yml +70 -0
- data/spec/fixtures/vcr/app_search/api_top_clicks_analytics.yml +55 -0
- data/spec/fixtures/vcr/app_search/api_top_clicks_analytics_query.yml +55 -0
- data/spec/fixtures/vcr/app_search/api_top_queries_analytics.yml +55 -0
- data/spec/fixtures/vcr/app_search/count_analytics.yml +55 -0
- data/spec/fixtures/vcr/app_search/create_and_update_document.yml +107 -0
- data/spec/fixtures/vcr/app_search/index_and_delete_document.yml +107 -0
- data/spec/fixtures/vcr/app_search/index_documents.yml +56 -0
- data/spec/fixtures/vcr/app_search/list_documents.yml +57 -0
- data/spec/fixtures/vcr/app_search/multi_query_search.yml +63 -0
- data/spec/fixtures/vcr/app_search/schema.yml +55 -0
- data/spec/fixtures/vcr/app_search/search.yml +57 -0
- data/spec/fixtures/vcr/app_search/single_query_search.yml +60 -0
- data/spec/fixtures/vcr/clear_user_permissions.yml +51 -0
- data/spec/fixtures/vcr/create_document.yml +54 -0
- data/spec/fixtures/vcr/create_engine.yml +55 -0
- data/spec/fixtures/vcr/delete_documents.yml +51 -0
- data/spec/fixtures/vcr/delete_engine.yml +55 -0
- data/spec/fixtures/vcr/get_engine.yml +55 -0
- data/spec/fixtures/vcr/index_documents.yml +53 -0
- data/spec/fixtures/vcr/list_engines.yml +55 -0
- data/spec/fixtures/vcr/list_permissions.yml +51 -0
- data/spec/fixtures/vcr/put_user_permissions.yml +99 -0
- data/spec/fixtures/vcr/remove_user_permissions.yml +16 -20
- data/spec/fixtures/vcr/user_permissions_empty.yml +51 -0
- data/spec/integration/enterprise_search_api_spec.rb +96 -0
- data/spec/spec_helper.rb +25 -14
- data/spec/webmock_requires.rb +4 -0
- data/spec/workplace-search/api_spec.rb +188 -0
- data/spec/workplace-search/client_spec.rb +69 -0
- metadata +207 -47
- data/.circleci/config.yml +0 -68
- data/.travis.yml +0 -15
- data/NOTICE.txt +0 -3
- data/lib/elastic/enterprise-search.rb +0 -7
- data/lib/elastic/enterprise-search/client/content_source_documents.rb +0 -46
- data/lib/elastic/enterprise-search/client/permissions.rb +0 -30
- data/logo-enterprise-search.png +0 -0
- data/spec/client/content_source_documents_spec.rb +0 -55
- data/spec/client/permissions_spec.rb +0 -75
- data/spec/configuration_spec.rb +0 -19
- data/spec/fixtures/vcr/async_create_or_update_document_success.yml +0 -51
- data/spec/fixtures/vcr/destroy_documents_success.yml +0 -51
- data/spec/fixtures/vcr/get_user_permissions.yml +0 -55
- data/spec/fixtures/vcr/list_all_permissions.yml +0 -55
- data/spec/fixtures/vcr/list_all_permissions_with_paging.yml +0 -55
- data/spec/fixtures/vcr/update_user_permissions.yml +0 -55
@@ -0,0 +1,51 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://localhost:3002/api/ws/v1/sources/content_source_key/permissions/enterprise_search/?user=enterprise_search
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: "{}"
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- 'elastic-enteprise-search-ruby/0.0.1 (RUBY_VERSION: 2.7.1; linux x86_64; elasticsearch-transport:
|
12
|
+
7.9.0)'
|
13
|
+
Content-Type:
|
14
|
+
- application/json
|
15
|
+
Authorization:
|
16
|
+
- Bearer access_token
|
17
|
+
Accept-Encoding:
|
18
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
19
|
+
Accept:
|
20
|
+
- "*/*"
|
21
|
+
response:
|
22
|
+
status:
|
23
|
+
code: 200
|
24
|
+
message: OK
|
25
|
+
headers:
|
26
|
+
X-Frame-Options:
|
27
|
+
- SAMEORIGIN
|
28
|
+
X-Xss-Protection:
|
29
|
+
- 1; mode=block
|
30
|
+
X-Content-Type-Options:
|
31
|
+
- nosniff
|
32
|
+
Content-Type:
|
33
|
+
- application/json;charset=utf-8
|
34
|
+
Etag:
|
35
|
+
- W/"eaf0aef29a99d5f9dda5844986aa3880"
|
36
|
+
Cache-Control:
|
37
|
+
- max-age=0, private, must-revalidate
|
38
|
+
X-Request-Id:
|
39
|
+
- fe4e4e34-d5c6-43ac-aae6-6f47a4e4c28d
|
40
|
+
X-Runtime:
|
41
|
+
- '0.063630'
|
42
|
+
Transfer-Encoding:
|
43
|
+
- chunked
|
44
|
+
Server:
|
45
|
+
- Jetty(9.4.30.v20200611)
|
46
|
+
body:
|
47
|
+
encoding: UTF-8
|
48
|
+
string: '{"user":"enterprise_search","permissions":[]}'
|
49
|
+
http_version:
|
50
|
+
recorded_at: Tue, 03 Nov 2020 23:15:20 GMT
|
51
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
|
22
|
+
describe Elastic::EnterpriseSearch::Client do
|
23
|
+
let(:host) { ENV['ELASTIC_ENTERPRISE_HOST'] || 'http://localhost:3002' }
|
24
|
+
let(:http_auth) do
|
25
|
+
{
|
26
|
+
user: ENV['ELASTIC_ENTERPRISE_USER'] || 'elastic',
|
27
|
+
password: ENV['ELASTIC_ENTERPRISE_PASSWORD'] || 'changeme'
|
28
|
+
}
|
29
|
+
end
|
30
|
+
let(:client) do
|
31
|
+
Elastic::EnterpriseSearch::Client.new(host: host, http_auth: http_auth)
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'API' do
|
35
|
+
context 'health' do
|
36
|
+
it 'makes GET request' do
|
37
|
+
response = client.health
|
38
|
+
|
39
|
+
expect(response.status).to eq 200
|
40
|
+
expect(response.body['name']).to be_a(String)
|
41
|
+
expect(response.body['version']).to have_key('number')
|
42
|
+
expect(response.body['jvm']).to have_key('gc')
|
43
|
+
expect(response.body['system']).to have_key('os_name')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'read only' do
|
48
|
+
it 'makes GET request' do
|
49
|
+
response = client.read_only
|
50
|
+
|
51
|
+
expect(response.status).to eq 200
|
52
|
+
expect(response.body).to have_key('enabled')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'put_read_only' do
|
57
|
+
it 'makes PUT request with enabled: true' do
|
58
|
+
response = client.put_read_only(enabled: true)
|
59
|
+
|
60
|
+
expect(response.status).to eq 200
|
61
|
+
expect(response.body).to have_key('enabled')
|
62
|
+
expect(response.body['enabled'])
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'makes PUT request with enabled: false' do
|
66
|
+
response = client.put_read_only(enabled: false)
|
67
|
+
|
68
|
+
expect(response.status).to eq 200
|
69
|
+
expect(response.body).to have_key('enabled')
|
70
|
+
expect(response.body['enabled']).to eq false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'stats' do
|
75
|
+
it 'makes GET request' do
|
76
|
+
response = client.stats
|
77
|
+
|
78
|
+
expect(response.status).to eq 200
|
79
|
+
expect(response.body).to have_key('app')
|
80
|
+
expect(response.body).to have_key('queues')
|
81
|
+
expect(response.body).to have_key('connectors')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'version' do
|
86
|
+
it 'makes GET request' do
|
87
|
+
response = client.version
|
88
|
+
|
89
|
+
expect(response.status).to eq 200
|
90
|
+
expect(response.body).to have_key('number')
|
91
|
+
expect(response.body).to have_key('build_hash')
|
92
|
+
expect(response.body).to have_key('build_date')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,28 +1,39 @@
|
|
1
|
-
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
require 'elastic/enterprise_search'
|
2
21
|
require 'rspec'
|
3
|
-
require 'webmock'
|
4
22
|
require 'vcr'
|
5
|
-
require 'awesome_print'
|
6
|
-
require 'elastic/enterprise-search'
|
7
|
-
|
8
23
|
|
9
24
|
RSpec.configure do |config|
|
10
25
|
# Run specs in random order to surface order dependencies. If you find an
|
11
26
|
# order dependency and want to debug it, you can fix the order by providing
|
12
27
|
# the seed, which is printed after each run.
|
13
28
|
# --seed 1234
|
14
|
-
config.order =
|
29
|
+
config.order = 'random'
|
30
|
+
|
31
|
+
config.add_formatter('documentation')
|
32
|
+
config.add_formatter('RspecJunitFormatter', 'enterprise-search-junit.xml')
|
15
33
|
|
16
34
|
VCR.configure do |c|
|
17
35
|
c.cassette_library_dir = 'spec/fixtures/vcr'
|
18
36
|
c.hook_into :webmock
|
19
|
-
|
20
|
-
|
21
|
-
config.before :each do
|
22
|
-
Elastic::EnterpriseSearch.endpoint = ENV["ENDPOINT"]
|
23
|
-
end
|
24
|
-
|
25
|
-
config.after :each do
|
26
|
-
Elastic::EnterpriseSearch.reset
|
37
|
+
c.allow_http_connections_when_no_cassette = true
|
27
38
|
end
|
28
39
|
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
|
22
|
+
describe Elastic::EnterpriseSearch::WorkplaceSearch::Client do
|
23
|
+
let(:host) { ENV['ELASTIC_ENTERPRISE_HOST'] || 'http://localhost:3002' }
|
24
|
+
let(:access_token) { ENV['ELASTIC_WORKPLACE_TOKEN'] || 'access_token' }
|
25
|
+
let(:content_source_key) { ENV['ELASTIC_WORKPLACE_SOURCE_KEY'] || 'content_source_key' }
|
26
|
+
let(:client) do
|
27
|
+
Elastic::EnterpriseSearch::WorkplaceSearch::Client.new(
|
28
|
+
host: host,
|
29
|
+
http_auth: access_token
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'documents' do
|
34
|
+
let(:documents) do
|
35
|
+
[
|
36
|
+
{ 'id' => '4e696e74656e646f203634',
|
37
|
+
'url' => 'https://www.elastic.co/blog/introducing-quick-start-guides-getting-started-with-elastic-enterprise-search-for-free',
|
38
|
+
'title' => 'Getting started with Elastic Enterprise Search for free',
|
39
|
+
'body' => 'this is a test' },
|
40
|
+
{
|
41
|
+
'id' => '47616d6520426f7920436f6c6f72',
|
42
|
+
'url' => 'https://www.elastic.co/workplace-search',
|
43
|
+
'title' => 'One-stop answer shop for the virtual workplace',
|
44
|
+
'body' => 'this is also a test'
|
45
|
+
}
|
46
|
+
]
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'indexes' do
|
50
|
+
VCR.use_cassette(:index_documents) do
|
51
|
+
response = client.index_documents(content_source_key, body: documents)
|
52
|
+
|
53
|
+
expect(response.status).to eq 200
|
54
|
+
expect(response.body)
|
55
|
+
.to eq(
|
56
|
+
{ 'results' =>
|
57
|
+
[
|
58
|
+
{ 'id' => '4e696e74656e646f203634', 'errors' => [] },
|
59
|
+
{ 'id' => '47616d6520426f7920436f6c6f72', 'errors' => [] }
|
60
|
+
] }
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'deletes' do
|
66
|
+
VCR.use_cassette(:index_documents) do
|
67
|
+
client.index_documents(content_source_key, body: documents)
|
68
|
+
end
|
69
|
+
|
70
|
+
VCR.use_cassette(:delete_documents) do
|
71
|
+
response = client.delete_documents(content_source_key, body: documents.map { |doc| doc['id'] })
|
72
|
+
expect(response.status).to eq 200
|
73
|
+
expect(response.body)
|
74
|
+
.to eq(
|
75
|
+
{ 'results' =>
|
76
|
+
[
|
77
|
+
{ 'id' => '4e696e74656e646f203634', 'success' => true },
|
78
|
+
{ 'id' => '47616d6520426f7920436f6c6f72', 'success' => true }
|
79
|
+
] }
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'permissions' do
|
86
|
+
let(:user) { 'enterprise_search' }
|
87
|
+
|
88
|
+
it 'lists permissions' do
|
89
|
+
VCR.use_cassette(:list_permissions) do
|
90
|
+
response = client.list_permissions(content_source_key)
|
91
|
+
|
92
|
+
expect(response.status).to eq 200
|
93
|
+
|
94
|
+
expect(response.body)
|
95
|
+
.to eq(
|
96
|
+
{ 'meta' =>
|
97
|
+
{ 'page' => { 'current' => 1, 'total_pages' => 1, 'total_results' => 1, 'size' => 25 } }, 'results' => [
|
98
|
+
{ 'user' => 'enterprise_search', 'permissions' => [] }
|
99
|
+
] }
|
100
|
+
)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'gets user permissions' do
|
105
|
+
clear_user_permissions
|
106
|
+
|
107
|
+
VCR.use_cassette(:user_permissions_empty) do
|
108
|
+
response = client.user_permissions(content_source_key, { user: user })
|
109
|
+
|
110
|
+
expect(response.status).to eq 200
|
111
|
+
|
112
|
+
expect(response.body)
|
113
|
+
.to eq(
|
114
|
+
{ 'user' => 'enterprise_search', 'permissions' => [] }
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def clear_user_permissions
|
120
|
+
VCR.use_cassette(:clear_user_permissions) do
|
121
|
+
client.put_user_permissions(
|
122
|
+
content_source_key,
|
123
|
+
{ permissions: [], user: user }
|
124
|
+
)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'updates user permissions' do
|
129
|
+
VCR.use_cassette(:put_user_permissions) do
|
130
|
+
response = client.add_user_permissions(
|
131
|
+
content_source_key,
|
132
|
+
{ permissions: ['testing', 'more', 'permissions'], user: user }
|
133
|
+
)
|
134
|
+
|
135
|
+
expect(response.status).to eq 200
|
136
|
+
|
137
|
+
expect(response.body)
|
138
|
+
.to eq(
|
139
|
+
{ 'user' => 'enterprise_search', 'permissions' => ['testing', 'more', 'permissions'] }
|
140
|
+
)
|
141
|
+
|
142
|
+
response = client.put_user_permissions(
|
143
|
+
content_source_key,
|
144
|
+
{ permissions: [], user: user }
|
145
|
+
)
|
146
|
+
|
147
|
+
expect(response.status).to eq 200
|
148
|
+
|
149
|
+
expect(response.body)
|
150
|
+
.to eq(
|
151
|
+
{ 'user' => 'enterprise_search', 'permissions' => [] }
|
152
|
+
)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'adds and removes permissions from a user' do
|
157
|
+
VCR.use_cassette(:add_user_permissions) do
|
158
|
+
permissions = ['permission1', 'permission2']
|
159
|
+
response = client.add_user_permissions(
|
160
|
+
content_source_key,
|
161
|
+
{ permissions: permissions, user: user }
|
162
|
+
)
|
163
|
+
|
164
|
+
expect(response.status).to eq 200
|
165
|
+
|
166
|
+
expect(response.body)
|
167
|
+
.to eq(
|
168
|
+
{ 'user' => 'enterprise_search', 'permissions' => ['permission1', 'permission2'] }
|
169
|
+
)
|
170
|
+
end
|
171
|
+
|
172
|
+
VCR.use_cassette(:remove_user_permissions) do
|
173
|
+
permissions = ['permission1', 'permission2']
|
174
|
+
response = client.remove_user_permissions(
|
175
|
+
content_source_key,
|
176
|
+
{ permissions: permissions, user: user }
|
177
|
+
)
|
178
|
+
|
179
|
+
expect(response.status).to eq 200
|
180
|
+
|
181
|
+
expect(response.body)
|
182
|
+
.to eq(
|
183
|
+
{ 'user' => 'enterprise_search', 'permissions' => [] }
|
184
|
+
)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Licensed to Elasticsearch B.V. under one or more contributor
|
2
|
+
# license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright
|
4
|
+
# ownership. Elasticsearch B.V. licenses this file to you under
|
5
|
+
# the Apache License, Version 2.0 (the "License"); you may
|
6
|
+
# not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
|
22
|
+
describe Elastic::EnterpriseSearch::WorkplaceSearch::Client do
|
23
|
+
let(:host) { 'https://localhost:8080' }
|
24
|
+
|
25
|
+
context 'dependant on EnterpriseSearch' do
|
26
|
+
let(:ent_client) { Elastic::EnterpriseSearch::Client.new(host: host) }
|
27
|
+
let(:workplace_client) { ent_client.workplace_search }
|
28
|
+
let(:access_token) { 'access_token' }
|
29
|
+
|
30
|
+
it 'initializes a workplace search client' do
|
31
|
+
expect(workplace_client).not_to be nil
|
32
|
+
expect(workplace_client).to be_a(Elastic::EnterpriseSearch::WorkplaceSearch::Client)
|
33
|
+
expect(workplace_client.host).to eq(host)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'sets up authentication during initialization' do
|
37
|
+
ent_client = Elastic::EnterpriseSearch::Client.new(host: host)
|
38
|
+
workplace_client = ent_client.workplace_search(http_auth: access_token)
|
39
|
+
expect(workplace_client.http_auth).to eq access_token
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'sets up authentication as a parameter' do
|
43
|
+
workplace_client.http_auth = access_token
|
44
|
+
expect(workplace_client.http_auth).to eq access_token
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'independent from EnterpriseSearch client' do
|
49
|
+
let(:workplace_client) { Elastic::EnterpriseSearch::WorkplaceSearch::Client.new(host: host) }
|
50
|
+
let(:access_token) { 'access_token' }
|
51
|
+
|
52
|
+
it 'initializes a workplace search client' do
|
53
|
+
expect(workplace_client).not_to be nil
|
54
|
+
expect(workplace_client).to be_a(Elastic::EnterpriseSearch::WorkplaceSearch::Client)
|
55
|
+
expect(workplace_client.host).to eq(host)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sets up authentication during initialization' do
|
59
|
+
ent_client = Elastic::EnterpriseSearch::Client.new(host: host)
|
60
|
+
workplace_client = ent_client.workplace_search(http_auth: access_token)
|
61
|
+
expect(workplace_client.http_auth).to eq access_token
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'sets up authentication as a parameter' do
|
65
|
+
workplace_client.http_auth = access_token
|
66
|
+
expect(workplace_client.http_auth).to eq access_token
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|