Skip to content

Commit

Permalink
clean up and improve test case
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Sep 4, 2023
1 parent 294cb20 commit 48e2603
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import lucee.commons.io.res.filter.ResourceFilter;
import lucee.commons.io.res.filter.ResourceNameFilter;
import lucee.loader.engine.CFMLEngine;
import lucee.loader.util.Util;

/**
* Helper class to build resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ public AmazonS3 create() throws S3Exception {
return builder.build();
}

public boolean isBackBlaze() {
return host != null && host.toLowerCase().indexOf(S3.BACKBLAZE.toLowerCase()) != -1;
}

public boolean isWasabi() {
return host != null && host.toLowerCase().indexOf(S3.WASABI.toLowerCase()) != -1;
}

public boolean isGoogle() {
return host != null && host.toLowerCase().indexOf(S3.GOOGLE.toLowerCase()) != -1;
}

private boolean isExpired() {
return (liveTimeout + System.currentTimeMillis()) < created;
}
Expand Down
7 changes: 5 additions & 2 deletions source/java/src/org/lucee/extension/resource/s3/S3.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ public class S3 {
public static final String DEFAULT_HOST = "s3.amazonaws.com";
public static final long DEFAULT_LIVE_TIMEOUT = 600000L;
public static final String GOOGLE = ".googleapis.com";
public static final String WASABI = ".wasabisys.com";
public static final String AWS = ".amazonaws.com";
public static final String BACKBLAZE = ".backblazeb2.com";
public static final String DREAM_IO = ".dream.io";

public static final String[] PROVIDERS = new String[] { ".amazonaws.com", ".wasabisys.com", ".backblazeb2.com", ".digitaloceanspaces.com", ".dream.io", GOOGLE };
public static final String[] PROVIDERS = new String[] { AWS, WASABI, BACKBLAZE, ".digitaloceanspaces.com", DREAM_IO, GOOGLE };

private static final ConcurrentHashMap<String, Object> tokens = new ConcurrentHashMap<String, Object>();
private static final int CHECK_INTERVALL = 1000;
Expand Down Expand Up @@ -2561,5 +2565,4 @@ public void shutdown() throws S3Exception {
public long getLiveTimeout() {
return liveTimeout;
}

}
16 changes: 9 additions & 7 deletions tests/tickets/LDEV4635.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {

// Blackbaze
it(title="Copying dir to a new s3 bucket, valid region name [us-east-1]", skip=Util::isBackBlazeNotSupported(), body=function( currentSpec ) {
copyToBucket(getCredentials("BackBlaze"), "us-east-1", "us-east-1" );
copyToBucket(getCredentials("BackBlaze"), "us-east-1", "" );
});

it(title="Copying dir to a new s3 bucket, valid region name [eu-west-1]", skip=Util::isBackBlazeNotSupported(), body=function( currentSpec ) {
copyToBucket(getCredentials("BackBlaze"), "eu-west-1", "eu-west-1" );
copyToBucket(getCredentials("BackBlaze"), "eu-west-1", "" );
});

it(title="Copying dir to a new s3 bucket, valid region name [eu-west-1]", skip=Util::isBackBlazeNotSupported(), body=function( currentSpec ) {
copyToBucket(getCredentials("BackBlaze"), "eu-west-1", "eu-central-1" ); // fails, can't current copy between regions LDEV-4639
copyToBucket(getCredentials("BackBlaze"), "eu-west-1", "" ); // fails, can't current copy between regions LDEV-4639
});

it(title="Copying dir to a new s3 bucket, invalid region name [down-under]", skip=Util::isBackBlazeNotSupported(), body=function( currentSpec ){
Expand Down Expand Up @@ -144,10 +144,12 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {
}

private function getCredentials(required string provider) localmode=true {
if("BackBlaze"==arguments.provider) return Util::getBackBlazeCredentials();
else if("AWS"==arguments.provider) return Util::getAWSCredentials();
else if("Wasabi"==arguments.provider) return Util::getWasabiCredentials();
else if("Google"==arguments.provider) return Util::getGoogleCredentials();
if("BackBlaze"==arguments.provider) local.credentials = Util::getBackBlazeCredentials();
else if("AWS"==arguments.provider) local.credentials = Util::getAWSCredentials();
else if("Wasabi"==arguments.provider) local.credentials = Util::getWasabiCredentials();
else if("Google"==arguments.provider) local.credentials = Util::getGoogleCredentials();
local.credentials.provider=arguments.provider;
return local.credentials;
}

}
Expand Down

0 comments on commit 48e2603

Please sign in to comment.