Skip to content

Commit 142327b

Browse files
committed
Fixed urlencode in params, Exception in test code generation, Utility fix with 404
1 parent 70eb847 commit 142327b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2436
-1356
lines changed

.ci/run-elasticsearch.sh

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Export the TEST_SUITE variable, eg. 'free' or 'platinum' defaults to 'free'.
88
# Export the NUMBER_OF_NODES variable to start more than 1 node
99

10-
# Version 1.3.0
10+
# Version 1.6.1
1111
# - Initial version of the run-elasticsearch.sh script
1212
# - Deleting the volume should not dependent on the container still running
1313
# - Fixed `ES_JAVA_OPTS` config
@@ -17,6 +17,10 @@
1717
# - Added 5 retries on docker pull for fixing transient network errors
1818
# - Added flags to make local CCR configurations work
1919
# - Added action.destructive_requires_name=false as the default will be true in v8
20+
# - Added ingest.geoip.downloader.enabled=false as it causes false positives in testing
21+
# - Moved ELASTIC_PASSWORD and xpack.security.enabled to the base arguments for "Security On by default"
22+
# - Use https only when TEST_SUITE is "platinum", when "free" use http
23+
# - Set xpack.security.enabled=false for "free" and xpack.security.enabled=true for "platinum"
2024

2125
script_path=$(dirname $(realpath -s $0))
2226
source $script_path/functions/imports.sh
@@ -30,6 +34,7 @@ cluster_name=${moniker}${suffix}
3034

3135
declare -a volumes
3236
environment=($(cat <<-END
37+
--env ELASTIC_PASSWORD=$elastic_password
3338
--env node.name=$es_node_name
3439
--env cluster.name=$cluster_name
3540
--env cluster.initial_master_nodes=$master_node_name
@@ -40,29 +45,44 @@ environment=($(cat <<-END
4045
--env path.repo=/tmp
4146
--env repositories.url.allowed_urls=http://snapshot.test*
4247
--env action.destructive_requires_name=false
43-
--env ELASTIC_PASSWORD=$elastic_password
44-
--env xpack.license.self_generated.type=trial
45-
--env xpack.security.enabled=true
46-
--env xpack.security.http.ssl.enabled=true
47-
--env xpack.security.http.ssl.verification_mode=certificate
48-
--env xpack.security.http.ssl.key=certs/testnode.key
49-
--env xpack.security.http.ssl.certificate=certs/testnode.crt
50-
--env xpack.security.http.ssl.certificate_authorities=certs/ca.crt
51-
--env xpack.security.transport.ssl.enabled=true
52-
--env xpack.security.transport.ssl.verification_mode=certificate
53-
--env xpack.security.transport.ssl.key=certs/testnode.key
54-
--env xpack.security.transport.ssl.certificate=certs/testnode.crt
55-
--env xpack.security.transport.ssl.certificate_authorities=certs/ca.crt
48+
--env ingest.geoip.downloader.enabled=false
49+
--env cluster.deprecation_indexing.enabled=false
50+
END
51+
))
52+
if [[ "$TEST_SUITE" == "platinum" ]]; then
53+
environment+=($(cat <<-END
54+
--env xpack.security.enabled=true
55+
--env xpack.license.self_generated.type=trial
56+
--env xpack.security.http.ssl.enabled=true
57+
--env xpack.security.http.ssl.verification_mode=certificate
58+
--env xpack.security.http.ssl.key=certs/testnode.key
59+
--env xpack.security.http.ssl.certificate=certs/testnode.crt
60+
--env xpack.security.http.ssl.certificate_authorities=certs/ca.crt
61+
--env xpack.security.transport.ssl.enabled=true
62+
--env xpack.security.transport.ssl.verification_mode=certificate
63+
--env xpack.security.transport.ssl.key=certs/testnode.key
64+
--env xpack.security.transport.ssl.certificate=certs/testnode.crt
65+
--env xpack.security.transport.ssl.certificate_authorities=certs/ca.crt
5666
END
5767
))
58-
volumes+=($(cat <<-END
59-
--volume $ssl_cert:/usr/share/elasticsearch/config/certs/testnode.crt
60-
--volume $ssl_key:/usr/share/elasticsearch/config/certs/testnode.key
61-
--volume $ssl_ca:/usr/share/elasticsearch/config/certs/ca.crt
68+
volumes+=($(cat <<-END
69+
--volume $ssl_cert:/usr/share/elasticsearch/config/certs/testnode.crt
70+
--volume $ssl_key:/usr/share/elasticsearch/config/certs/testnode.key
71+
--volume $ssl_ca:/usr/share/elasticsearch/config/certs/ca.crt
72+
END
73+
))
74+
else
75+
environment+=($(cat <<-END
76+
--env xpack.security.enabled=false
77+
--env xpack.security.http.ssl.enabled=false
6278
END
6379
))
80+
fi
6481

65-
cert_validation_flags="--insecure --cacert /usr/share/elasticsearch/config/certs/ca.crt --resolve ${es_node_name}:443:127.0.0.1"
82+
cert_validation_flags=""
83+
if [[ "$TEST_SUITE" == "platinum" ]]; then
84+
cert_validation_flags="--insecure --cacert /usr/share/elasticsearch/config/certs/ca.crt --resolve ${es_node_name}:443:127.0.0.1"
85+
fi
6686

6787
# Pull the container, retry on failures up to 5 times with
6888
# short delays between each attempt. Fixes most transient network errors.

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function getResponseException(): bool
143143
* @return Elasticsearch|Promise
144144
*/
145145
public function sendRequest(RequestInterface $request)
146-
{
146+
{
147147
// If async returns a Promise
148148
if ($this->getAsync()) {
149149
if ($this->getElasticMetaHeader()) {

src/Endpoints/AsyncSearch.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ class AsyncSearch extends AbstractEndpoint
4242
public function delete(array $params = [])
4343
{
4444
$this->checkRequiredParameters(['id'], $params);
45-
$url = "/_async_search/{$params['id']}";
45+
$url = '/_async_search/' . urlencode((string) $params['id']);
4646
$method = 'DELETE';
4747

48-
return $this->client->sendRequest($this->createRequest($method, $url, $params['body'] ?? []));
48+
$headers = array (
49+
'Accept' => 'application/json',
50+
);
51+
return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? []));
4952
}
5053

5154

@@ -66,10 +69,13 @@ public function delete(array $params = [])
6669
public function get(array $params = [])
6770
{
6871
$this->checkRequiredParameters(['id'], $params);
69-
$url = "/_async_search/{$params['id']}";
72+
$url = '/_async_search/' . urlencode((string) $params['id']);
7073
$method = 'GET';
7174

72-
return $this->client->sendRequest($this->createRequest($method, $url, $params['body'] ?? []));
75+
$headers = array (
76+
'Accept' => 'application/json',
77+
);
78+
return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? []));
7379
}
7480

7581

@@ -87,10 +93,13 @@ public function get(array $params = [])
8793
public function status(array $params = [])
8894
{
8995
$this->checkRequiredParameters(['id'], $params);
90-
$url = "/_async_search/status/{$params['id']}";
96+
$url = '/_async_search/status/' . urlencode((string) $params['id']);
9197
$method = 'GET';
9298

93-
return $this->client->sendRequest($this->createRequest($method, $url, $params['body'] ?? []));
99+
$headers = array (
100+
'Accept' => 'application/json',
101+
);
102+
return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? []));
94103
}
95104

96105

@@ -150,12 +159,16 @@ public function status(array $params = [])
150159
public function submit(array $params = [])
151160
{
152161
if (isset($params['index'])) {
153-
$url = "/{$params['index']}/_async_search";
162+
$url = '/' . urlencode((string) $params['index']) . '/_async_search';
154163
$method = 'POST';
155164
} else {
156-
$url = "/_async_search";
165+
$url = '/_async_search';
157166
$method = 'POST';
158167
}
159-
return $this->client->sendRequest($this->createRequest($method, $url, $params['body'] ?? []));
168+
$headers = array (
169+
'Accept' => 'application/json',
170+
'Content-Type' => 'application/json',
171+
);
172+
return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? []));
160173
}
161174
}

src/Endpoints/Autoscaling.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ class Autoscaling extends AbstractEndpoint
4242
public function deleteAutoscalingPolicy(array $params = [])
4343
{
4444
$this->checkRequiredParameters(['name'], $params);
45-
$url = "/_autoscaling/policy/{$params['name']}";
45+
$url = '/_autoscaling/policy/' . urlencode((string) $params['name']);
4646
$method = 'DELETE';
4747

48-
return $this->client->sendRequest($this->createRequest($method, $url, $params['body'] ?? []));
48+
$headers = array (
49+
'Accept' => 'application/json',
50+
);
51+
return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? []));
4952
}
5053

5154

@@ -56,10 +59,13 @@ public function deleteAutoscalingPolicy(array $params = [])
5659
*/
5760
public function getAutoscalingCapacity(array $params = [])
5861
{
59-
$url = "/_autoscaling/capacity";
62+
$url = '/_autoscaling/capacity';
6063
$method = 'GET';
6164

62-
return $this->client->sendRequest($this->createRequest($method, $url, $params['body'] ?? []));
65+
$headers = array (
66+
'Accept' => 'application/json',
67+
);
68+
return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? []));
6369
}
6470

6571

@@ -77,10 +83,13 @@ public function getAutoscalingCapacity(array $params = [])
7783
public function getAutoscalingPolicy(array $params = [])
7884
{
7985
$this->checkRequiredParameters(['name'], $params);
80-
$url = "/_autoscaling/policy/{$params['name']}";
86+
$url = '/_autoscaling/policy/' . urlencode((string) $params['name']);
8187
$method = 'GET';
8288

83-
return $this->client->sendRequest($this->createRequest($method, $url, $params['body'] ?? []));
89+
$headers = array (
90+
'Accept' => 'application/json',
91+
);
92+
return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? []));
8493
}
8594

8695

@@ -99,9 +108,13 @@ public function getAutoscalingPolicy(array $params = [])
99108
public function putAutoscalingPolicy(array $params = [])
100109
{
101110
$this->checkRequiredParameters(['name','body'], $params);
102-
$url = "/_autoscaling/policy/{$params['name']}";
111+
$url = '/_autoscaling/policy/' . urlencode((string) $params['name']);
103112
$method = 'PUT';
104113

105-
return $this->client->sendRequest($this->createRequest($method, $url, $params['body'] ?? []));
114+
$headers = array (
115+
'Accept' => 'application/json',
116+
'Content-Type' => 'application/json',
117+
);
118+
return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? []));
106119
}
107120
}

0 commit comments

Comments
 (0)