From 4f7dad8da2ce425aa3dcc11afad79701a26f54ed Mon Sep 17 00:00:00 2001 From: jaymode Date: Sat, 2 Apr 2016 18:01:46 -0400 Subject: [PATCH] security: handle null values for full name and email This commit adds logic so that we properly handle null tokens for full name and email. Closes elastic/elasticsearch#1887 Original commit: elastic/x-pack-elasticsearch@e03188c29f4ae3de105cf83ad5b344f0b2a727c2 --- .../action/user/PutUserRequestBuilder.java | 4 +- .../user/PutUserRequestBuilderTests.java | 116 ++++++++++++++++++ 2 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/action/user/PutUserRequestBuilderTests.java diff --git a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequestBuilder.java b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequestBuilder.java index a9f73bd757d..11f061c2d9b 100644 --- a/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequestBuilder.java +++ b/elasticsearch/x-pack/shield/src/main/java/org/elasticsearch/shield/action/user/PutUserRequestBuilder.java @@ -111,14 +111,14 @@ public class PutUserRequestBuilder extends ActionRequestBuilder builder.source("kibana4", new BytesArray(json.getBytes(StandardCharsets.UTF_8)))); + assertThat(e.getMessage(), containsString("expected field [full_name] to be of type string")); + } + + public void testInvalidEmail() throws IOException { + final String json = "{\n" + + " \"roles\": [\n" + + " \"kibana4\"\n" + + " ],\n" + + " \"full_name\": \"Kibana User\",\n" + + " \"email\": [ \"kibana@elastic.co\" ],\n" + + " \"metadata\": {}\n" + + "}"; + + PutUserRequestBuilder builder = new PutUserRequestBuilder(mock(Client.class)); + ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, + () -> builder.source("kibana4", new BytesArray(json.getBytes(StandardCharsets.UTF_8)))); + assertThat(e.getMessage(), containsString("expected field [email] to be of type string")); + } +}