|
44 | 44 | import org.junit.Before; |
45 | 45 | import org.junit.Test; |
46 | 46 |
|
| 47 | +import java.util.List; |
47 | 48 | import java.util.ArrayList; |
48 | 49 |
|
49 | 50 | import static org.hamcrest.Matchers.equalTo; |
@@ -152,6 +153,93 @@ public void testSimpleWorkflow() { |
152 | 153 | assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true)); |
153 | 154 | assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false)); |
154 | 155 | } |
| 156 | + |
| 157 | + @Test |
| 158 | + public void testEncryption() { |
| 159 | +Client client = client(); |
| 160 | +logger.info("--> creating s3 repository with bucket[{}] and path [{}]", cluster().getInstance(Settings.class).get("repositories.s3.bucket"), basePath); |
| 161 | +PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo") |
| 162 | +.setType("s3").setSettings(ImmutableSettings.settingsBuilder() |
| 163 | +.put("base_path", basePath) |
| 164 | +.put("chunk_size", randomIntBetween(1000, 10000)) |
| 165 | +.put("server_side_encryption", true) |
| 166 | +).get(); |
| 167 | +assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); |
| 168 | + |
| 169 | +createIndex("test-idx-1", "test-idx-2", "test-idx-3"); |
| 170 | +ensureGreen(); |
| 171 | + |
| 172 | +logger.info("--> indexing some data"); |
| 173 | +for (int i = 0; i < 100; i++) { |
| 174 | + index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i); |
| 175 | + index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i); |
| 176 | + index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i); |
| 177 | +} |
| 178 | +refresh(); |
| 179 | +assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); |
| 180 | +assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L)); |
| 181 | +assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(100L)); |
| 182 | + |
| 183 | +logger.info("--> snapshot"); |
| 184 | +CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-3").get(); |
| 185 | +assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); |
| 186 | +assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards())); |
| 187 | + |
| 188 | +assertThat(client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS)); |
| 189 | + |
| 190 | +Settings settings = cluster().getInstance(Settings.class); |
| 191 | +Settings bucket = settings.getByPrefix("repositories.s3."); |
| 192 | +AmazonS3 s3Client = cluster().getInstance(AwsS3Service.class).client( |
| 193 | +bucket.get("region", settings.get("repositories.s3.region")), |
| 194 | +bucket.get("access_key", settings.get("cloud.aws.access_key")), |
| 195 | +bucket.get("secret_key", settings.get("cloud.aws.secret_key"))); |
| 196 | + |
| 197 | + String bucketName = bucket.get("bucket"); |
| 198 | +logger.info("--> verify encryption for bucket [{}], prefix [{}]", bucketName, basePath); |
| 199 | +List<S3ObjectSummary> summaries = s3Client.listObjects(bucketName, basePath).getObjectSummaries(); |
| 200 | +for (S3ObjectSummary summary : summaries) { |
| 201 | + assertThat(s3Client.getObjectMetadata(bucketName, summary.getKey()).getServerSideEncryption(), equalTo("AES256")); |
| 202 | +} |
| 203 | + |
| 204 | +logger.info("--> delete some data"); |
| 205 | +for (int i = 0; i < 50; i++) { |
| 206 | + client.prepareDelete("test-idx-1", "doc", Integer.toString(i)).get(); |
| 207 | +} |
| 208 | +for (int i = 50; i < 100; i++) { |
| 209 | + client.prepareDelete("test-idx-2", "doc", Integer.toString(i)).get(); |
| 210 | +} |
| 211 | +for (int i = 0; i < 100; i += 2) { |
| 212 | + client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get(); |
| 213 | +} |
| 214 | +refresh(); |
| 215 | +assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(50L)); |
| 216 | +assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(50L)); |
| 217 | +assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L)); |
| 218 | + |
| 219 | +logger.info("--> close indices"); |
| 220 | +client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get(); |
| 221 | + |
| 222 | +logger.info("--> restore all indices from the snapshot"); |
| 223 | +RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet(); |
| 224 | +assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); |
| 225 | + |
| 226 | +ensureGreen(); |
| 227 | +assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); |
| 228 | +assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L)); |
| 229 | +assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L)); |
| 230 | + |
| 231 | +// Test restore after index deletion |
| 232 | +logger.info("--> delete indices"); |
| 233 | +cluster().wipeIndices("test-idx-1", "test-idx-2"); |
| 234 | +logger.info("--> restore one index after deletion"); |
| 235 | +restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-2").execute().actionGet(); |
| 236 | +assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0)); |
| 237 | +ensureGreen(); |
| 238 | +assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L)); |
| 239 | +ClusterState clusterState = client.admin().cluster().prepareState().get().getState(); |
| 240 | +assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true)); |
| 241 | +assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false)); |
| 242 | + } |
155 | 243 |
|
156 | 244 | /** |
157 | 245 | * This test verifies that the test configuration is set up in a manner that |
|
0 commit comments