Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HADOOP-16626. S3A ITestRestrictedReadAccess fails #1587

Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,35 @@
*/
public class S3AContract extends AbstractBondedFSContract {

/**
* Test resource with the contract bindings used in the standard
* contract tests: {@value}.
*/
public static final String CONTRACT_XML = "contract/s3a.xml";

/**
* Instantiate, adding the s3a.xml contract file.
* This may force a reload of the entire configuration, so interferes with
* any code which has removed bucket overrides.
* @param conf configuration.
*/
public S3AContract(Configuration conf) {
this(conf, true);
}

/**
* Instantiate, optionally adding the s3a.xml contract file.
* This may force a reload of the entire configuration, so interferes with
* any code which has removed bucket overrides.
* @param conf configuration.
* @param addContractResource should the s3a.xml file be added?
*/
public S3AContract(Configuration conf, boolean addContractResource) {
super(conf);
//insert the base features
addConfResource(CONTRACT_XML);
if (addContractResource) {
addConfResource(CONTRACT_XML);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.hadoop.fs.s3a;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.contract.AbstractFSContract;
import org.apache.hadoop.fs.contract.AbstractFSContractTestBase;
Expand Down Expand Up @@ -46,12 +47,16 @@ public abstract class AbstractS3ATestBase extends AbstractFSContractTestBase

@Override
protected AbstractFSContract createContract(Configuration conf) {
return new S3AContract(conf);
return new S3AContract(conf, false);
}

@Override
public void setup() throws Exception {
Thread.currentThread().setName("setup");
// force load the local FS -not because we want the FS, but we need all
// filesystems which add default configuration resources to do it before
// our tests start adding/removing options. See HADOOP-16626.
FileSystem.getLocal(new Configuration());
super.setup();
}

Expand Down Expand Up @@ -83,7 +88,8 @@ protected int getTestTimeoutMillis() {
*/
@Override
protected Configuration createConfiguration() {
return S3ATestUtils.prepareTestConfiguration(super.createConfiguration());
Configuration conf = super.createConfiguration();
return S3ATestUtils.prepareTestConfiguration(conf);
}

protected Configuration getConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,7 @@ public static Path createTestPath(Path defVal) {
*/
public static void assumeS3GuardState(boolean shouldBeEnabled,
Configuration originalConf) throws URISyntaxException {
boolean isEnabled = getTestPropertyBool(originalConf, TEST_S3GUARD_ENABLED,
originalConf.getBoolean(TEST_S3GUARD_ENABLED, false));
boolean isEnabled = isS3GuardTestPropertySet(originalConf);
Assume.assumeThat("Unexpected S3Guard test state:"
+ " shouldBeEnabled=" + shouldBeEnabled
+ " and isEnabled=" + isEnabled,
Expand All @@ -462,13 +461,22 @@ public static void assumeS3GuardState(boolean shouldBeEnabled,
shouldBeEnabled, Is.is(!usingNullImpl));
}

/**
* Is the test option for S3Guard set?
* @param conf configuration to examine.
* @return true if the config or system property turns s3guard tests on
*/
public static boolean isS3GuardTestPropertySet(final Configuration conf) {
return getTestPropertyBool(conf, TEST_S3GUARD_ENABLED,
conf.getBoolean(TEST_S3GUARD_ENABLED, false));
}

/**
* Conditionally set the S3Guard options from test properties.
* @param conf configuration
*/
public static void maybeEnableS3Guard(Configuration conf) {
if (getTestPropertyBool(conf, TEST_S3GUARD_ENABLED,
conf.getBoolean(TEST_S3GUARD_ENABLED, false))) {
if (isS3GuardTestPropertySet(conf)) {
// S3Guard is enabled.
boolean authoritative = getTestPropertyBool(conf,
TEST_S3GUARD_AUTHORITATIVE,
Expand Down Expand Up @@ -758,8 +766,9 @@ public static void removeBucketOverrides(final String bucket,
for (String option : options) {
final String stripped = option.substring("fs.s3a.".length());
String target = bucketPrefix + stripped;
if (conf.get(target) != null) {
LOG.debug("Removing option {}", target);
String v = conf.get(target);
if (v != null) {
LOG.debug("Removing option {}; was {}", target, v);
conf.unset(target);
}
}
Expand Down Expand Up @@ -1273,6 +1282,16 @@ public static boolean metadataStorePersistsAuthoritativeBit(MetadataStore ms)
return Boolean.valueOf(persists);
}

/**
* Set the metadata store of a filesystem instance to the given
* store, via a package-private setter method.
* @param fs filesystem.
* @param ms metastore
*/
public static void setMetadataStore(S3AFileSystem fs, MetadataStore ms) {
fs.setMetadataStore(ms);
}

public static void checkListingDoesNotContainPath(S3AFileSystem fs, Path filePath)
throws IOException {
final RemoteIterator<LocatedFileStatus> listIter =
Expand Down
Loading