diff --git a/.gitignore b/.gitignore index 71da7e5..95c7c9f 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ modules/** # log files logs/** +.idea/ diff --git a/ModuleConfig.cfc b/ModuleConfig.cfc index 6fee81b..b8296e6 100644 --- a/ModuleConfig.cfc +++ b/ModuleConfig.cfc @@ -52,7 +52,8 @@ component { defaultBlockPublicAcls : false, defaultIgnorePublicAcls : false, defaultBlockPublicPolicy : false, - defaultRestrictPublicBuckets : false + defaultRestrictPublicBuckets : false, + urlStyle : "path" }; } @@ -90,6 +91,9 @@ component { .initArg( name = "defaultRestrictPublicBuckets", value = variables.settings.defaultRestrictPublicBuckets + ).initArg( + name = "urlStyle", + value = variables.settings.urlStyle ); binder.map( "Sv4Util@s3sdk" ).to( "#moduleMapping#.models.AmazonS3" ); diff --git a/models/AmazonS3.cfc b/models/AmazonS3.cfc index 535ffdc..58363dc 100644 --- a/models/AmazonS3.cfc +++ b/models/AmazonS3.cfc @@ -22,7 +22,7 @@ * s3_accessKey : The Amazon access key * s3_secretKey : The Amazon secret key * s3_encryption_charset : encryptyion charset (Optional, defaults to utf-8) - * s3_ssl : Whether to use ssl on all cals or not (Optional, defaults to false) + * s3_ssl : Whether to use ssl on all calls or not (Optional, defaults to false) */ component accessors="true" singleton { @@ -59,7 +59,7 @@ component accessors="true" singleton { property name="defaultIgnorePublicAcls"; property name="defaultBlockPublicPolicy"; property name="defaultRestrictPublicBuckets"; - + property name="urlStyle"; // STATIC Contsants this.ACL_PRIVATE = "private"; @@ -109,6 +109,7 @@ component accessors="true" singleton { * @defaultIgnorePublicAcls Specifies whether Amazon S3 should block public bucket policies for this bucket. Setting this element to TRUE causes Amazon S3 to reject calls to PUT Bucket policy if the specified bucket policy allows public access. * @defaultBlockPublicPolicy Specifies whether Amazon S3 should ignore public ACLs for this bucket and objects in this bucket. Setting this element to TRUE causes Amazon S3 to ignore all public ACLs on this bucket and objects in this bucket. * @defaultRestrictPublicBuckets Specifies whether Amazon S3 should restrict public bucket policies for this bucket. Setting this element to TRUE restricts access to this bucket to only AWS service principals and authorized users within this account if the bucket has a public policy. + * @urlStyle Specifies the format of the URL whether it is the `path` format or `virtual` format. Defaults to path. For more information see https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html * * @return An AmazonS3 instance. */ @@ -139,7 +140,8 @@ component accessors="true" singleton { boolean defaultBlockPublicAcls = false, boolean defaultIgnorePublicAcls = false, boolean defaultBlockPublicPolicy = false, - boolean defaultRestrictPublicBuckets = false + boolean defaultRestrictPublicBuckets = false, + string urlStyle = "path" ){ if ( arguments.awsDomain == "amazonaws.com" && arguments.awsRegion == "" ) { arguments.awsRegion = "us-east-1"; @@ -176,6 +178,7 @@ component accessors="true" singleton { variables.defaultIgnorePublicAcls = arguments.defaultIgnorePublicAcls; variables.defaultBlockPublicPolicy = arguments.defaultBlockPublicPolicy; variables.defaultRestrictPublicBuckets = arguments.defaultRestrictPublicBuckets; + variables.urlStyle = arguments.urlStyle; // Construct the SSL Domain setSSL( arguments.ssl ); @@ -261,21 +264,34 @@ component accessors="true" singleton { /** * This function builds variables.UrlEndpoint and variables.URLEndpointHostname according to credentials and ssl configuration, usually called after init() for you automatically. */ - AmazonS3 function buildUrlEndpoint(){ + AmazonS3 function buildUrlEndpoint( string bucketName ){ // Build accordingly var URLEndPointProtocol = ( variables.ssl ) ? "https://" : "http://"; var hostnameComponents = []; - if ( variables.awsDomain contains "amazonaws.com" ) { - hostnameComponents.append( "s3" ); - } - if ( len( variables.awsRegion ) ) { - hostnameComponents.append( variables.awsRegion ); + if ( variables.urlStyle == "path" ) { + if ( variables.awsDomain contains "amazonaws.com" ) { + hostnameComponents.append( "s3" ); + } + if ( len( variables.awsRegion ) ) { + hostnameComponents.append( variables.awsRegion ); + } + } else if ( variables.urlStyle == "virtual" ) { + if ( variables.awsDomain contains "amazonaws.com" ) { + if ( !isNull( arguments.bucketName ) ) { + hostnameComponents.append( arguments.bucketName ); + } + + hostnameComponents.append( "s3" ); + + if ( len( variables.awsRegion ) ) { + hostnameComponents.append( variables.awsRegion ); + } + } } hostnameComponents.append( variables.awsDomain ); variables.URLEndpointHostname = arrayToList( hostnameComponents, "." ); variables.URLEndpoint = URLEndpointProtocol & variables.URLEndpointHostname; - return this; } @@ -325,7 +341,7 @@ component accessors="true" singleton { if ( results.error ) { throw( message = "Error making Amazon REST Call", detail = results.message ); } - + // Should this return whatever comes from AWS? It seems like hardcoding a potentially wrong answer is not a good idea. if ( len( results.response.LocationConstraint.XMLText ) ) { return results.response.LocationConstraint.XMLText; } @@ -858,7 +874,7 @@ component accessors="true" singleton { var finalized = s3Request( method = "POST", - resource = arguments.bucketName & "/" & arguments.uri, + resource = buildKeyName( arguments.uri, arguments.bucketName ), timeout = arguments.HTTPTimeout, parameters = { "uploadId" : uploadId }, body = finalizeBody @@ -875,7 +891,7 @@ component accessors="true" singleton { } catch ( any e ) { s3Request( method = "DELETE", - resource = arguments.bucketName & "/" & arguments.uri, + resource = buildKeyName( arguments.uri, arguments.bucketName ), timeout = arguments.HTTPTimeout, parameters = { "uploadId" : uploadId } ); @@ -1034,7 +1050,7 @@ component accessors="true" singleton { var results = s3Request( method = "PUT", - resource = arguments.bucketName & "/" & arguments.uri, + resource = buildKeyName( arguments.uri, arguments.bucketName ), body = arguments.data, timeout = arguments.HTTPTimeout, headers = headers @@ -1065,7 +1081,7 @@ component accessors="true" singleton { var headers = applyEncryptionHeaders( {}, arguments ); var results = s3Request( method = "HEAD", - resource = arguments.bucketName & "/" & arguments.uri, + resource = buildKeyName( arguments.uri, arguments.bucketName ), headers = headers ); @@ -1096,7 +1112,7 @@ component accessors="true" singleton { requireBucketName( arguments.bucketName ); var results = s3Request( method = "GET", - resource = arguments.bucketName & "/" & arguments.uri, + resource = buildKeyName( arguments.uri, arguments.bucketName ), parameters = { "acl" : "" }, throwOnError = throwOnError ); @@ -1139,7 +1155,7 @@ component accessors="true" singleton { requireBucketName( arguments.bucketName ); var results = s3Request( method = "HEAD", - resource = arguments.bucketName & "/" & arguments.uri, + resource = buildKeyName( arguments.uri, arguments.bucketName ), throwOnError = false ); var status_code = results.responseHeader.status_code ?: 0; @@ -1292,7 +1308,7 @@ component accessors="true" singleton { return s3Request( method = "POST", - resource = arguments.bucketName & "/" & arguments.uri, + resource = buildKeyName( arguments.uri, arguments.bucketName ), timeout = arguments.HTTPTimeout, headers = headers, parameters = { "uploads" : true }, @@ -1320,6 +1336,7 @@ component accessors="true" singleton { required string uri, string encryptionKey = variables.defaultEncryptionKey ){ + buildUrlEndpoint( arguments.bucketName ); requireBucketName( arguments.bucketName ); var headers = applyEncryptionHeaders( {}, arguments ); @@ -1327,7 +1344,7 @@ component accessors="true" singleton { var results = s3Request( method = "GET", headers = headers, - resource = arguments.bucketName & "/" & arguments.uri + resource = buildKeyName( arguments.uri, arguments.bucketName ) ); return results; } @@ -1365,7 +1382,7 @@ component accessors="true" singleton { var results = s3Request( method = "GET", headers = headers, - resource = arguments.bucketName & "/" & arguments.uri, + resource = buildKeyName( arguments.uri, arguments.bucketName ), filename = arguments.filepath, timeout = arguments.HTTPTimeout, getAsBinary = arguments.getAsBinary, @@ -1393,7 +1410,10 @@ component accessors="true" singleton { boolean function deleteObject( required string bucketName = variables.defaultBucketName, required string uri ){ requireBucketName( arguments.bucketName ); - var results = s3Request( method = "DELETE", resource = arguments.bucketName & "/" & arguments.uri ); + var results = s3Request( + method = "DELETE", + resource = buildKeyName( arguments.uri, arguments.bucketName ) + ); return results.responseheader.status_code == 204; } @@ -1861,7 +1881,7 @@ component accessors="true" singleton { * Determines mime type from the file extension * * @filePath The path to the file stored in S3. - * + * * @return string */ string function getFileMimeType( required string filePath ){ @@ -1883,4 +1903,15 @@ component accessors="true" singleton { return contentType; } + + /** + * Creates the s3 key name based on the format (path or virtual) from the bucket name and the object key + * + * @url The key for the file in question + * @bucketName The name of the bucket to use. Not needed if the urlStyle is `virtual` + **/ + function buildKeyName( required string uri, string bucketName = "" ){ + return variables.urlStyle == "path" ? arguments.bucketName & ( arguments.bucketName.len() ? "/" : "" ) & arguments.uri : arguments.uri; + } + } diff --git a/readme.md b/readme.md index df63480..953ecb5 100644 --- a/readme.md +++ b/readme.md @@ -53,7 +53,8 @@ This SDK will be installed into a directory called `s3sdk` and then the SDK can * @debug Used to turn debugging on or off outside of logbox. Defaults to false. * @defaultEncryptionAlgorithm The default server side encryption algorithm to use. Usually "AES256". Not needed if using custom defaultEncryptionKey * @defaultEncryptionKey The default base64 encoded AES 356 bit key for server side encryption. - * + * @urlStyle Specifies the format of the URL whether it is the `path` format or `virtual` format. Defaults to path. For more information see https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html + * * @return An AmazonS3 instance. */ public AmazonS3 function init( @@ -75,6 +76,7 @@ public AmazonS3 function init( boolean debug= false, string defaultEncryptionAlgorithm = "", string defaultEncryptionKey = "", + string urlStyle = "path" ) ``` @@ -125,7 +127,9 @@ moduleSettings = { // SSL mode or not on cfhttp calls and when generating put/get authenticated URLs: Defaults to true ssl = true, // Throw exceptions when s3 requests fail, else it swallows them up. - throwOnRequestError : true + throwOnRequestError : true, + // What format of endpoint to use whether path or virtual + urlStyle = "path" } }; ``` diff --git a/server-adobe@2023.json b/server-adobe@2023.json index 5347f8e..96b4e94 100644 --- a/server-adobe@2023.json +++ b/server-adobe@2023.json @@ -2,7 +2,7 @@ "name":"s3sdk-adobe@2023", "app":{ "serverHomeDirectory":".engine/adobe2023", - "cfengine":"adobe@2023.0.0-beta.1" + "cfengine":"adobe@2023.0.4+330500" }, "web":{ "http":{ diff --git a/test-harness/config/Coldbox.cfc b/test-harness/config/Coldbox.cfc index 2de244d..d5b096e 100644 --- a/test-harness/config/Coldbox.cfc +++ b/test-harness/config/Coldbox.cfc @@ -1,96 +1,91 @@ -component{ +component { // Configure ColdBox Application function configure(){ - // coldbox directives coldbox = { - //Application Setup - appName = "Module Tester", - - //Development Settings - reinitPassword = "", - handlersIndexAutoReload = true, - modulesExternalLocation = [], - - //Implicit Events - defaultEvent = "", - requestStartHandler = "", - requestEndHandler = "", - applicationStartHandler = "", - applicationEndHandler = "", - sessionStartHandler = "", - sessionEndHandler = "", - missingTemplateHandler = "", - - //Error/Exception Handling - exceptionHandler = "", - onInvalidEvent = "", - customErrorTemplate = "/coldbox/system/exceptions/Whoops.cfm", - - //Application Aspects - handlerCaching = false, - eventCaching = false + // Application Setup + appName : "Module Tester", + // Development Settings + reinitPassword : "", + handlersIndexAutoReload : true, + modulesExternalLocation : [], + // Implicit Events + defaultEvent : "", + requestStartHandler : "", + requestEndHandler : "", + applicationStartHandler : "", + applicationEndHandler : "", + sessionStartHandler : "", + sessionEndHandler : "", + missingTemplateHandler : "", + // Error/Exception Handling + exceptionHandler : "", + onInvalidEvent : "", + customErrorTemplate : "/coldbox/system/exceptions/Whoops.cfm", + // Application Aspects + handlerCaching : false, + eventCaching : false }; settings = { - "targetEngine" : getSystemSetting( "ENGINE", "localhost" ), + "targetEngine" : getSystemSetting( "ENGINE", "localhost" ), "coldBoxVersion" : getSystemSetting( "COLDBOX_VERSION", "" ) }; // environment settings, create a detectEnvironment() method to detect it yourself. // create a function with the name of the environment so it can be executed if that environment is detected // the value of the environment is a list of regex patterns to match the cgi.http_host. - environments = { - development = "localhost,127\.0\.0\.1" - }; + environments = { development : "localhost,127\.0\.0\.1" }; // Module Directives modules = { // An array of modules names to load, empty means all of them - include = [], + include : [], // An array of modules names to NOT load, empty means none - exclude = [] + exclude : [] }; - //Register interceptors as an array, we need order + // Register interceptors as an array, we need order interceptors = []; - //LogBox DSL + // LogBox DSL logBox = { // Define Appenders - appenders = { - console={ - class="coldbox.system.logging.appenders.ConsoleAppender" - }, - files={class="coldbox.system.logging.appenders.RollingFileAppender", - properties = { - filename = "tester", filePath="/#appMapping#/logs" - } + appenders : { + console : { class : "coldbox.system.logging.appenders.ConsoleAppender" }, + files : { + class : "coldbox.system.logging.appenders.RollingFileAppender", + properties : { filename : "tester", filePath : "/#appMapping#/logs" } } }, // Root Logger - root = { levelmax="DEBUG", appenders="*" }, + root : { levelmax : "DEBUG", appenders : "*" }, // Implicit Level Categories - info = [ "coldbox.system" ], - debug = [ "s3sdk" ] + info : [ "coldbox.system" ], + debug : [ "s3sdk" ] }; moduleSettings = { - s3sdk = { + s3sdk : { // Settings - accessKey : getSystemSetting( "AWS_ACCESS_KEY" ), - secretKey : getSystemSetting( "AWS_ACCESS_SECRET" ), - defaultBucketName : getSystemSetting( - "AWS_DEFAULT_BUCKET_NAME", - "ortus3-s3sdk-bdd-#replace( settings.targetEngine, "@", "-" )#-#reReplace( settings.coldBoxVersion, '[^a-zA-Z0-9]', '', 'all' )#" - ), - awsRegion : getSystemSetting( "AWS_REGION" ), - awsDomain : getSystemSetting( "AWS_DOMAIN" ), - ssl : getSystemSetting( "AWS_SSL", true ) + accessKey : getSystemSetting( "AWS_ACCESS_KEY" ), + secretKey : getSystemSetting( "AWS_ACCESS_SECRET" ), + defaultBucketName : getSystemSetting( + "AWS_DEFAULT_BUCKET_NAME", + "ortus3-s3sdk-bdd-#replace( settings.targetEngine, "@", "-" )#-#reReplace( + settings.coldBoxVersion, + "[^a-zA-Z0-9]", + "", + "all" + )#" + ), + awsRegion : getSystemSetting( "AWS_REGION" ), + awsDomain : getSystemSetting( "AWS_DOMAIN" ), + ssl : getSystemSetting( "AWS_SSL", true ), + urlStyle : getsystemSetting( "AWS_URLSTYLE", "path" ) } }; - } function afterAspectsLoad( event, interceptData ){ @@ -99,4 +94,4 @@ .registerModule( moduleName = request.MODULE_NAME, invocationPath = "moduleroot" ); } -} \ No newline at end of file +} diff --git a/test-harness/tests/specs/AmazonS3Spec.cfc b/test-harness/tests/specs/AmazonS3Spec.cfc index b99a5d8..1589328 100644 --- a/test-harness/tests/specs/AmazonS3Spec.cfc +++ b/test-harness/tests/specs/AmazonS3Spec.cfc @@ -19,21 +19,15 @@ component extends="coldbox.system.testing.BaseTestCase" { awsDomain = moduleSettings.awsDomain, ssl = moduleSettings.ssl, defaultBucketName = moduleSettings.defaultBucketName, - defaultObjectOwnership = moduleSettings.defaultObjectOwnership + defaultObjectOwnership = moduleSettings.defaultObjectOwnership, + urlStyle = "path" ); getWirebox().autowire( s3 ); prepareMock( s3 ); s3.$property( propertyName = "log", mock = createLogStub() ); - //try { - s3.putBucket( testBucket ); - //} catch ( any e ) { - // writeDump( - // var = "Error putting test bucket, maybe cached: #e.message# #e.detail#", - // output = "console" - // ); - //} + s3.putBucket( testBucket ); } private function prepTmpFolder(){ @@ -97,7 +91,7 @@ component extends="coldbox.system.testing.BaseTestCase" { contentType = "auto" ); var md = s3.getObjectInfo( testBucket, "example.txt" ); - // debug( md ); + expect( md ).notToBeEmpty(); expect( md[ "Content-Type" ] ).toBe( "text/plain" ); } ); @@ -119,7 +113,7 @@ component extends="coldbox.system.testing.BaseTestCase" { ); expect( resp.contains( "multipart" ) ).toBeTrue(); var md = s3.getObjectInfo( testBucket, uploadFileName ); - // debug( md ); + expect( md ).notToBeEmpty(); expect( md[ "Content-Length" ] ).toBe( fileSize ); expect( md[ "Content-Type" ] ).toBe( "text/plain" ); @@ -146,7 +140,7 @@ component extends="coldbox.system.testing.BaseTestCase" { "Hello, space world!" ); var md = s3.getObjectInfo( testBucket, "Word Doc Tests.txt" ); - // debug( md ); + expect( md ).notToBeEmpty(); } ); @@ -570,7 +564,7 @@ component extends="coldbox.system.testing.BaseTestCase" { var get = s3.getObject( testBucket, "presignedput.txt" ); expect( get.error ).toBeFalse(); - // toString() since there is no content type set in thnis test, Adobe doesn't send back the file as a string, but a byte output stream + // toString() since there is no content type set in this test, Adobe doesn't send back the file as a string, but a byte output stream expect( toString( get.response ) ).toBe( "Pre-Signed Put!" ); } ); diff --git a/test-harness/tests/specs/models/AmazonS3/buildKeyName.cfc b/test-harness/tests/specs/models/AmazonS3/buildKeyName.cfc new file mode 100644 index 0000000..ae5b676 --- /dev/null +++ b/test-harness/tests/specs/models/AmazonS3/buildKeyName.cfc @@ -0,0 +1,56 @@ +/** + * My BDD Test + */ +component extends="coldbox.system.testing.BaseTestCase" { + + /*********************************** LIFE CYCLE Methods ***********************************/ + this.unloadColdbox = false; + // executes before all suites+specs in the run() method + function beforeAll(){ + super.beforeAll(); + } + + /*********************************** BDD SUITES ***********************************/ + + function run( testResults, testBox ){ + describe( "The buildKeyName function should...", function(){ + beforeEach( function(){ + uri = mockData( $num = 1, $type = "words:1" )[ 1 ]; + bucketName = mockData( $num = 1, $type = "words:1" )[ 1 ]; + var moduleSettings = getWirebox().getInstance( "box:moduleSettings:s3sdk" ); + + testObj = new s3sdk.models.AmazonS3( + accessKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + secretKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsRegion = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsDomain = mockdata( $num = 1, $type = "words:1" )[ 1 ], + ssl = true, + defaultBucketName = mockdata( $num = 1, $type = "words:1" )[ 1 ], + defaultObjectOwnership = mockdata( $num = 1, $type = "words:1" )[ 1 ] + ); + } ); + it( "If the urlStyle is path and a bucket is submitted, return bucket\uri", function(){ + testObj.setUrlStyle( "path" ); + testme = testObj.buildKeyName( uri, bucketName ); + expect( testme ).tobe( "#bucketName#/#uri#" ); + } ); + it( "If the urlStyle is path and a bucket is not submitted, return uri", function(){ + testObj.setUrlStyle( "path" ); + testme = testObj.buildKeyName( uri ); + expect( testme ).tobe( uri ); + } ); + it( "If the urlStyle is path and the bucket is an empty string, return uri", function(){ + testObj.setUrlStyle( "path" ); + testme = testObj.buildKeyName( uri, "" ); + expect( testme ).tobe( uri ); + } ); + it( "If the urlStyle is virtual, return uri", function(){ + testObj.setUrlStyle( "virtual" ); + testme = testObj.buildKeyName( uri, bucketname ); + expect( testme ).tobe( uri ); + } ); + } ); + } + +} + diff --git a/test-harness/tests/specs/models/AmazonS3/buildUrlEndpoint.cfc b/test-harness/tests/specs/models/AmazonS3/buildUrlEndpoint.cfc new file mode 100644 index 0000000..23d59a5 --- /dev/null +++ b/test-harness/tests/specs/models/AmazonS3/buildUrlEndpoint.cfc @@ -0,0 +1,104 @@ +/** + * My BDD Test + */ +component extends="coldbox.system.testing.BaseTestCase" { + + /*********************************** LIFE CYCLE Methods ***********************************/ + this.unloadColdbox = false; + // executes before all suites+specs in the run() method + function beforeAll(){ + super.beforeAll(); + } + + /*********************************** BDD SUITES ***********************************/ + + function run( testResults, testBox ){ + // all your suites go here. + describe( "The buildUrlEndpoint function should ...", function(){ + beforeEach( function(){ + domain = mockData( $num = 1, $type = "words:1" )[ 1 ]; + region = mockData( $num = 1, $type = "words:1" )[ 1 ]; + bucketName = mockData( $num = 1, $type = "words:1" )[ 1 ]; + keyName = mockData( $num = 1, $type = "words:1" )[ 1 ]; + testObj = new s3sdk.models.AmazonS3( + accessKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + secretKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsRegion = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsDomain = mockdata( $num = 1, $type = "words:1" )[ 1 ], + ssl = true, + defaultBucketName = mockdata( $num = 1, $type = "words:1" )[ 1 ], + defaultObjectOwnership = mockdata( $num = 1, $type = "words:1" )[ 1 ] + ); + testObj.setAwsRegion( region ); + } ); + it( "If the urlStyle is path - the default - , build according to https://s3.region-code.amazonaws.com/bucket-name/key-name", function(){ + testObj.setUrlStyle( "path" ); + testObj.setawsDomain( "amazonaws.com" ); + var testme = testObj.buildUrlEndpoint( bucketName ); + expect( testme.getURLEndpointHostname() ).tobe( "s3.#region#.amazonaws.com" ); + expect( testme.getURLEndpoint() ).tobe( "https://s3.#region#.amazonaws.com" ); + } ); + it( "If the urlStyle is path and the domain is not amazonaws.com, do not include s3", function(){ + testObj.setUrlStyle( "path" ); + testObj.setawsDomain( domain ); + var testme = testObj.buildUrlEndpoint( bucketName ); + expect( testme.getURLEndpointHostname() ).tobe( "#region#.#domain#" ); + expect( testme.getURLEndpoint() ).tobe( "https://#region#.#domain#" ); + } ); + it( "If the urlStyle is path and the region is empty, do not include it", function(){ + testObj.setUrlStyle( "path" ); + testObj.setawsDomain( "amazonaws.com" ); + testObj.setawsRegion( "" ); + var testme = testObj.buildUrlEndpoint( bucketName ); + expect( testme.getURLEndpointHostname() ).tobe( "s3.amazonaws.com" ); + expect( testme.getURLEndpoint() ).tobe( "https://s3.amazonaws.com" ); + } ); + it( "If the urlStyle is virtual and the domain has amazonaws.com, build according to https://bucket-name.s3.region-code.amazonaws.com/key-name", function(){ + testObj.setUrlStyle( "virtual" ); + testObj.setawsDomain( "amazonaws.com" ); + var testme = testObj.buildUrlEndpoint( bucketName ); + expect( testme.getURLEndpointHostname() ).tobe( "#bucketName#.s3.#region#.amazonaws.com" ); + expect( testme.getURLEndpoint() ).tobe( "https://#bucketName#.s3.#region#.amazonaws.com" ); + } ); + it( "If the urlStyle is virtual and the domain has amazonaws.com, but a bucket name is not submitted, do not include it", function(){ + testObj.setUrlStyle( "virtual" ); + testObj.setawsDomain( "amazonaws.com" ); + var testme = testObj.buildUrlEndpoint(); + expect( testme.getURLEndpointHostname() ).tobe( "s3.#region#.amazonaws.com" ); + expect( testme.getURLEndpoint() ).tobe( "https://s3.#region#.amazonaws.com" ); + } ); + it( "If the urlStyle is virtual and the domain has amazonaws.com, but a region is not set, do not include it", function(){ + testObj.setUrlStyle( "virtual" ); + testObj.setawsDomain( "amazonaws.com" ); + testObj.setawsRegion( "" ); + var testme = testObj.buildUrlEndpoint( bucketName ); + expect( testme.getURLEndpointHostname() ).tobe( "#bucketName#.s3.amazonaws.com" ); + expect( testme.getURLEndpoint() ).tobe( "https://#bucketName#.s3.amazonaws.com" ); + } ); + it( "If the urlStyle is virtual and the domain does not have amazonaws.com, do not alter the domain name", function(){ + testObj.setUrlStyle( "virtual" ); + testObj.setawsDomain( "mydomain.com" ); + testObj.setawsRegion( "" ); + var testme = testObj.buildUrlEndpoint( bucketName ); + expect( testme.getURLEndpointHostname() ).tobe( "mydomain.com" ); + expect( testme.getURLEndpoint() ).tobe( "https://mydomain.com" ); + } ); + it( "If the urlStyle is path and the domain does not have amazonaws.com, do not alter the domain name", function(){ + testObj.setUrlStyle( "virtual" ); + testObj.setawsDomain( "mydomain.com" ); + testObj.setawsRegion( "" ); + var testme = testObj.buildUrlEndpoint( bucketName ); + expect( testme.getURLEndpointHostname() ).tobe( "mydomain.com" ); + expect( testme.getURLEndpoint() ).tobe( "https://mydomain.com" ); + } ); + it( "It should return an instance of AmazonS3", function(){ + testObj.setUrlStyle( "path" ); + testObj.setawsDomain( "amazonaws.com" ); + var testme = testObj.buildUrlEndpoint( bucketName ); + expect( testme ).tobeInstanceOf( "AmazonS3" ); + } ); + } ); + } + +} + diff --git a/test-harness/tests/specs/models/AmazonS3/createSignatureUtil.cfc b/test-harness/tests/specs/models/AmazonS3/createSignatureUtil.cfc new file mode 100644 index 0000000..10d265c --- /dev/null +++ b/test-harness/tests/specs/models/AmazonS3/createSignatureUtil.cfc @@ -0,0 +1,41 @@ +/** + * My BDD Test + */ +component extends="coldbox.system.testing.BaseTestCase" { + + /*********************************** LIFE CYCLE Methods ***********************************/ + this.unloadColdbox = false; + // executes before all suites+specs in the run() method + function beforeAll(){ + super.beforeAll(); + } + + /*********************************** BDD SUITES ***********************************/ + + function run( testResults, testBox ){ + // all your suites go here. + describe( "The createSignatureUtil function should...", function(){ + beforeEach( function(){ + testObj = new s3sdk.models.AmazonS3( + accessKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + secretKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsRegion = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsDomain = mockdata( $num = 1, $type = "words:1" )[ 1 ], + ssl = true, + defaultBucketName = mockdata( $num = 1, $type = "words:1" )[ 1 ], + defaultObjectOwnership = mockdata( $num = 1, $type = "words:1" )[ 1 ] + ); + } ); + it( "If V2 is submitted, return SV2Util", function(){ + testme = testObj.createSignatureUtil( "V2" ); + expect( testme ).tobeInstanceOf( "Sv2Util" ); + } ); + it( "If V4 is submitted, return SV2Util", function(){ + testme = testObj.createSignatureUtil( "V4" ); + expect( testme ).tobeInstanceOf( "Sv4Util" ); + } ); + } ); + } + +} + diff --git a/test-harness/tests/specs/models/AmazonS3/getBucketLocation.cfc b/test-harness/tests/specs/models/AmazonS3/getBucketLocation.cfc new file mode 100644 index 0000000..c91b581 --- /dev/null +++ b/test-harness/tests/specs/models/AmazonS3/getBucketLocation.cfc @@ -0,0 +1,80 @@ +/** + * My BDD Test + */ +component extends="coldbox.system.testing.BaseTestCase" { + + /*********************************** LIFE CYCLE Methods ***********************************/ + this.unloadColdbox = false; + // executes before all suites+specs in the run() method + function beforeAll(){ + super.beforeAll(); + } + + /*********************************** BDD SUITES ***********************************/ + + function run( testResults, testBox ){ + // all your suites go here. + describe( "The setAwsRegion function should...", function(){ + beforeEach( function(){ + accessKey = mockData( $num = 1, $type = "words:1" )[ 1 ]; + secretKey = mockData( $num = 1, $type = "words:1" )[ 1 ]; + bucketName = mockData( $num = 1, $type = "words:1" )[ 1 ]; + + testObj = testObj = new s3sdk.models.AmazonS3( + accessKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + secretKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsRegion = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsDomain = mockdata( $num = 1, $type = "words:1" )[ 1 ], + ssl = true, + defaultBucketName = mockdata( $num = 1, $type = "words:1" )[ 1 ], + defaultObjectOwnership = mockdata( $num = 1, $type = "words:1" )[ 1 ] + ); + prepareMock( testObj ); + testObj.setAccessKey( accessKey ); + testObj.setSecretKey( secretKey ); + testObj.$( method = "requireBucketName" ); + testObj.$( method = "s3Request", returns = createResponse() ); + } ); + it( "Should call requireBucketName 1x ", function(){ + testme = testObj.getBucketLocation( bucketName ); + expect( testObj.$count( "requireBucketName" ) ).tobe( 1 ); + } ); + it( "Should call s3Request 1x ", function(){ + testme = testObj.getBucketLocation( bucketName ); + expect( testObj.$count( "s3Request" ) ).tobe( 1 ); + } ); + it( "If an error is returned from s3Request, it should throw an error with the message from s3 as the error message ", function(){ + var message = mockdata( $num = 1, $type = "words:10" )[ 1 ]; + testObj.$( method = "s3Request", returns = createResponse( error = true, message = message ) ); + expect( function(){ + testObj.getBucketLocation( bucketName ); + } ).tothrow( type = "application", message = message ); + } ); + } ); + } + + function createResponse( + required boolean error = false, + string location = "", + message = "" + ){ + return { + "response" : xmlParse( " + #arguments.location#" ), + "message" : arguments.message, + "error" : arguments.error, + "responseheader" : { + "Date" : "Tue, 19 Sep 2023 16:09:11 GMT", + "Server" : "AmazonS3", + "Transfer-Encoding" : "chunked", + "x-amz-id-2" : "8CxOH41yj+NlQLaKGmgFGRpImXai9QnR+nNT5biih8eeYBWSZ1R65tUW1C6uw9eTvj5435wzWPg=", + "x-amz-request-id" : "263PWVHD32Y7P5Q9", + "status_code" : 200, + "Content-Type" : "application/xml", + "explanation" : "OK" + } + }; + } + +} + diff --git a/test-harness/tests/specs/models/AmazonS3/init.cfc b/test-harness/tests/specs/models/AmazonS3/init.cfc new file mode 100644 index 0000000..2a39fed --- /dev/null +++ b/test-harness/tests/specs/models/AmazonS3/init.cfc @@ -0,0 +1,226 @@ +/** + * My BDD Test + */ +component extends="coldbox.system.testing.BaseTestCase" { + + /*********************************** LIFE CYCLE Methods ***********************************/ + this.unloadColdbox = false; + // executes before all suites+specs in the run() method + function beforeAll(){ + super.beforeAll(); + } + + /*********************************** BDD SUITES ***********************************/ + + function run( testResults, testBox ){ + // all your suites go here. + describe( "By default the init function should...", function(){ + beforeEach( function(){ + accessKey = mockData( $num = 1, $type = "words:1" )[ 1 ]; + secretKey = mockData( $num = 1, $type = "words:1" )[ 1 ]; + + testObj = new s3sdk.models.AmazonS3( + accessKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + secretKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsRegion = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsDomain = mockdata( $num = 1, $type = "words:1" )[ 1 ], + ssl = true, + defaultBucketName = mockdata( $num = 1, $type = "words:1" )[ 1 ], + defaultObjectOwnership = mockdata( $num = 1, $type = "words:1" )[ 1 ] + ); + prepareMock( testObj ); + testObj.$( method = "createSignatureUtil" ); + } ); + it( "Have the accessKey set", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getAccessKey() ).tobe( accessKey ); + } ); + it( "Have the secretKey set", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getSecretKey() ).tobe( secretKey ); + } ); + it( "Have the awsDomain set to amazonaws.com", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getawsDomain() ).tobe( "amazonaws.com" ); + } ); + it( "Have the awsRegion set to awsRegion.com", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getawsRegion() ).tobe( "us-east-1" ); + } ); + it( "Have the encryptionCharset set to UTF-8", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getencryptionCharset() ).tobe( "UTF-8" ); + } ); + it( "Have the ssl set to true", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getssl() ).tobeTrue(); + } ); + it( "Have the defaultTimeOut set to 300", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultTimeOut() ).tobe( 300 ); + } ); + it( "Have the defaultDelimiter set to /", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultDelimiter() ).tobe( "/" ); + } ); + it( "Have the defaultBucketName set to blank string", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultBucketName().len() ).tobe( 0 ); + } ); + it( "Have the defaultCacheControl set to no-store, no-cache, must-revalidate", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultCacheControl() ).tobe( "no-store, no-cache, must-revalidate" ); + } ); + it( "Have the defaultStorageClass set to no-store, no-cache, must-revalidate", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultStorageClass() ).tobe( "STANDARD" ); + } ); + it( "Have the defaultACL set to public-read", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultACL() ).tobe( "public-read" ); + } ); + it( "Have the throwOnRequestError set to true", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getthrowOnRequestError() ).tobeTrue(); + } ); + it( "Have the retriesOnError set to 3", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getretriesOnError() ).tobe( 3 ); + } ); + it( "Have the autoContentType set to false", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getautoContentType() ).tobeFalse(); + } ); + it( "Have the autoMD5 set to an empty string since the signature type defaults to V4", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getautoMD5().len() ).tobe( 0 ); + } ); + it( "Have the serviceName set to s3", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getserviceName() ).tobe( "s3" ); + } ); + it( "Have the defaultEncryptionAlgorithm set to an empty string", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultEncryptionAlgorithm().len() ).toBe( 0 ); + } ); + it( "Have the defaultEncryptionKey set to an empty string", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultEncryptionKey().len() ).tobe( 0 ); + } ); + it( "Have the multiPartByteThreshold set to 5242880", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getmultiPartByteThreshold() ).tobe( 5242880 ); + } ); + it( "Have the defaultObjectOwnership set to ObjectWriter", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultObjectOwnership() ).tobe( "ObjectWriter" ); + } ); + it( "Have the defaultBlockPublicAcls set to False", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultBlockPublicAcls() ).tobeFalse(); + } ); + it( "Have the defaultIgnorePublicAcls set to False", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultIgnorePublicAcls() ).tobeFalse(); + } ); + it( "Have the defaultBlockPublicPolicy set to False", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultBlockPublicPolicy() ).tobeFalse(); + } ); + it( "Have the defaultRestrictPublicBuckets set to False", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getdefaultRestrictPublicBuckets() ).tobeFalse(); + } ); + it( "Have the urlStyle set to path", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.geturlStyle() ).tobe( "path" ); + } ); + it( "Have the ssl set to true", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getSSL() ).tobeTrue(); + } ); + it( "Have the mimeTypes set", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testme.getMimeTypes() ).tobeTypeOf( "struct" ); + + var mimeTypes = returnMimeTypes(); + var targetMimeTypes = testme.getMimeTypes(); + expect( mimeTypes.keyArray().len() ).tobe( targetMimeTypes.keyArray().len() ); + mimeTypes.each( function( item ){ + expect( targetMimeTypes ).toHaveKey( item ); + expect( targetMimeTypes[ item ] ).tobe( + mimeTypes[ item ], + "#mimeTypes[ item ]# was the wrong value in " + ); + } ); + targetMimeTypes.each( function( item ){ + expect( mimeTypes ).toHaveKey( item ); + expect( mimeTypes[ item ] ).tobe( + targetMimeTypes[ item ], + "#targetMimeTypes[ item ]# changed - update test reference " + ); + } ); + } ); + + + + it( "If the signature type is V2, Have the autoMD5 set to auto", function(){ + testme = testObj.init( + accessKey = accessKey, + secretKey = secretKey, + signatureType = "V2" + ); + expect( testme.getautoMD5() ).tobe( "auto" ); + } ); + it( "If arguments.autoMD5 is true , Have the autoMD5 set to auto", function(){ + testme = testObj.init( + accessKey = accessKey, + secretKey = secretKey, + autoMD5 = true + ); + expect( testme.getautoMD5() ).tobe( "auto" ); + } ); + it( "Should call createSignatureUtil 1x passing in the submitted signatureType", function(){ + testme = testObj.init( accessKey = accessKey, secretKey = secretKey ); + expect( testObj.$count( "createSignatureUtil" ) ).tobe( 1 ); + expect( testObj._mockCallLoggers ).toHaveKey( "createSignatureUtil" ); + expect( testObj._mockCallLoggers.createSignatureUtil.len() ).tobe( 1 ); + // expect(testObj._mockCallLoggers.createSignatureUtil[1].len()).tobe(1); + expect( testObj._mockCallLoggers.createSignatureUtil[ 1 ][ 1 ] ).tobe( "v4" ); + } ); + } ); + } + + function returnMimeTypes(){ + return { + htm : "text/html", + html : "text/html", + js : "application/x-javascript", + txt : "text/plain", + xml : "text/xml", + rss : "application/rss+xml", + css : "text/css", + gz : "application/x-gzip", + gif : "image/gif", + jpe : "image/jpeg", + jpeg : "image/jpeg", + jpg : "image/jpeg", + png : "image/png", + swf : "application/x-shockwave-flash", + ico : "image/x-icon", + flv : "video/x-flv", + doc : "application/msword", + xls : "application/vnd.ms-excel", + pdf : "application/pdf", + htc : "text/x-component", + svg : "image/svg+xml", + eot : "application/vnd.ms-fontobject", + ttf : "font/ttf", + otf : "font/opentype", + woff : "application/font-woff", + woff2 : "font/woff2" + }; + } + +} + diff --git a/test-harness/tests/specs/models/AmazonS3/requireBucketName.cfc b/test-harness/tests/specs/models/AmazonS3/requireBucketName.cfc new file mode 100644 index 0000000..3c3f8d2 --- /dev/null +++ b/test-harness/tests/specs/models/AmazonS3/requireBucketName.cfc @@ -0,0 +1,53 @@ +/** + * My BDD Test + */ +component extends="coldbox.system.testing.BaseTestCase" { + + /*********************************** LIFE CYCLE Methods ***********************************/ + this.unloadColdbox = false; + // executes before all suites+specs in the run() method + function beforeAll(){ + super.beforeAll(); + } + + /*********************************** BDD SUITES ***********************************/ + + function run( testResults, testBox ){ + // all your suites go here. + describe( "The setAwsRegion function should...", function(){ + beforeEach( function(){ + bucketName = mockdata( $num = 1, $type = "words:1" )[ 1 ]; + testObj = testObj = new s3sdk.models.AmazonS3( + accessKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + secretKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsRegion = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsDomain = mockdata( $num = 1, $type = "words:1" )[ 1 ], + ssl = true, + defaultBucketName = mockdata( $num = 1, $type = "words:1" )[ 1 ], + defaultObjectOwnership = mockdata( $num = 1, $type = "words:1" )[ 1 ] + ); + makePublic( + testObj, + "requireBucketName", + "requireBucketNamePublic" + ); + } ); + it( "If a bucketname is submitted, do nothing", function(){ + testme = testObj.requireBucketNamePublic( bucketName ); + expect( isNull( testme ) ).tobeTrue(); + } ); + it( "If a bucketname is blank, throw an application error", function(){ + expect( function(){ + testObj.requireBucketNamePublic( "" ); + } ).toThrow( "application" ); + } ); + it( "If a bucketname is null, throw an application error", function(){ + expect( function(){ + testObj.requireBucketNamePublic(); + } ).toThrow( "application" ); + } ); + } ); + } + +} + diff --git a/test-harness/tests/specs/models/AmazonS3/setAuth.cfc b/test-harness/tests/specs/models/AmazonS3/setAuth.cfc new file mode 100644 index 0000000..00e075b --- /dev/null +++ b/test-harness/tests/specs/models/AmazonS3/setAuth.cfc @@ -0,0 +1,44 @@ +/** + * My BDD Test + */ +component extends="coldbox.system.testing.BaseTestCase" { + + /*********************************** LIFE CYCLE Methods ***********************************/ + this.unloadColdbox = false; + // executes before all suites+specs in the run() method + function beforeAll(){ + super.beforeAll(); + } + + /*********************************** BDD SUITES ***********************************/ + + function run( testResults, testBox ){ + // all your suites go here. + describe( "The setAuth function should...", function(){ + beforeEach( function(){ + accessKey = mockData( $num = 1, $type = "words:1" )[ 1 ]; + secretKey = mockData( $num = 1, $type = "words:1" )[ 1 ]; + + testObj = new s3sdk.models.AmazonS3( + accessKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + secretKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsRegion = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsDomain = mockdata( $num = 1, $type = "words:1" )[ 1 ], + ssl = true, + defaultBucketName = mockdata( $num = 1, $type = "words:1" )[ 1 ], + defaultObjectOwnership = mockdata( $num = 1, $type = "words:1" )[ 1 ] + ); + } ); + it( "Set the accessKey submitted", function(){ + testme = testObj.setAuth( accessKey, secretKey ); + expect( testme.getAccessKey() ).tobe( accessKey ); + } ); + it( "Set the secretKey submitted", function(){ + testme = testObj.setAuth( accessKey, secretKey ); + expect( testme.getSecretKey() ).tobe( secretKey ); + } ); + } ); + } + +} + diff --git a/test-harness/tests/specs/models/AmazonS3/setAwsDomain.cfc b/test-harness/tests/specs/models/AmazonS3/setAwsDomain.cfc new file mode 100644 index 0000000..65c68a9 --- /dev/null +++ b/test-harness/tests/specs/models/AmazonS3/setAwsDomain.cfc @@ -0,0 +1,45 @@ +/** + * My BDD Test + */ +component extends="coldbox.system.testing.BaseTestCase" { + + /*********************************** LIFE CYCLE Methods ***********************************/ + this.unloadColdbox = false; + // executes before all suites+specs in the run() method + function beforeAll(){ + super.beforeAll(); + } + + /*********************************** BDD SUITES ***********************************/ + + function run( testResults, testBox ){ + // all your suites go here. + describe( "The setAWSDomain function should...", function(){ + beforeEach( function(){ + domain = mockData( $num = 1, $type = "words:1" )[ 1 ]; + + testObj = new s3sdk.models.AmazonS3( + accessKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + secretKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsRegion = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsDomain = mockdata( $num = 1, $type = "words:1" )[ 1 ], + ssl = true, + defaultBucketName = mockdata( $num = 1, $type = "words:1" )[ 1 ], + defaultObjectOwnership = mockdata( $num = 1, $type = "words:1" )[ 1 ] + ); + prepareMock( testObj ); + testObj.$( method = "buildUrlEndpoint", returns = testObj ); + } ); + it( "Set the domain submitted", function(){ + testme = testObj.setAwsDomain( domain ); + expect( testme.getAwsDomain() ).tobe( domain ); + } ); + it( "call buildUrlEndpoint 1x", function(){ + testme = testObj.setAwsDomain( domain ); + expect( testObj.$count( "buildUrlEndpoint" ) ).tobe( 1 ); + } ); + } ); + } + +} + diff --git a/test-harness/tests/specs/models/AmazonS3/setAwsRegion.cfc b/test-harness/tests/specs/models/AmazonS3/setAwsRegion.cfc new file mode 100644 index 0000000..cff6327 --- /dev/null +++ b/test-harness/tests/specs/models/AmazonS3/setAwsRegion.cfc @@ -0,0 +1,45 @@ +/** + * My BDD Test + */ +component extends="coldbox.system.testing.BaseTestCase" { + + /*********************************** LIFE CYCLE Methods ***********************************/ + this.unloadColdbox = false; + // executes before all suites+specs in the run() method + function beforeAll(){ + super.beforeAll(); + } + + /*********************************** BDD SUITES ***********************************/ + + function run( testResults, testBox ){ + // all your suites go here. + describe( "The setAwsRegion function should...", function(){ + beforeEach( function(){ + region = mockData( $num = 1, $type = "words:1" )[ 1 ]; + + testObj = new s3sdk.models.AmazonS3( + accessKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + secretKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsRegion = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsDomain = mockdata( $num = 1, $type = "words:1" )[ 1 ], + ssl = true, + defaultBucketName = mockdata( $num = 1, $type = "words:1" )[ 1 ], + defaultObjectOwnership = mockdata( $num = 1, $type = "words:1" )[ 1 ] + ); + prepareMock( testObj ); + testObj.$( method = "buildUrlEndpoint", returns = testObj ); + } ); + it( "Set the region submitted", function(){ + testme = testObj.setAwsRegion( region ); + expect( testme.getAwsREgion() ).tobe( region ); + } ); + it( "call buildUrlEndpoint 1x", function(){ + testme = testObj.setAwsRegion( region ); + expect( testObj.$count( "buildUrlEndpoint" ) ).tobe( 1 ); + } ); + } ); + } + +} + diff --git a/test-harness/tests/specs/models/AmazonS3/setSSL.cfc b/test-harness/tests/specs/models/AmazonS3/setSSL.cfc new file mode 100644 index 0000000..3908414 --- /dev/null +++ b/test-harness/tests/specs/models/AmazonS3/setSSL.cfc @@ -0,0 +1,43 @@ +/** + * My BDD Test + */ +component extends="coldbox.system.testing.BaseTestCase" { + + /*********************************** LIFE CYCLE Methods ***********************************/ + this.unloadColdbox = false; + // executes before all suites+specs in the run() method + function beforeAll(){ + super.beforeAll(); + } + + /*********************************** BDD SUITES ***********************************/ + + function run( testResults, testBox ){ + // all your suites go here. + describe( "The setAwsRegion function should...", function(){ + beforeEach( function(){ + testObj = new s3sdk.models.AmazonS3( + accessKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + secretKey = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsRegion = mockdata( $num = 1, $type = "words:1" )[ 1 ], + awsDomain = mockdata( $num = 1, $type = "words:1" )[ 1 ], + ssl = true, + defaultBucketName = mockdata( $num = 1, $type = "words:1" )[ 1 ], + defaultObjectOwnership = mockdata( $num = 1, $type = "words:1" )[ 1 ] + ); + prepareMock( testObj ); + testObj.$( method = "buildUrlEndpoint", returns = testObj ); + } ); + it( "Set the ssl submitted", function(){ + testme = testObj.setSSL( true ); + expect( testme.getSSL() ).tobe( true ); + } ); + it( "call buildUrlEndpoint 1x", function(){ + testme = testObj.setSSL( true ); + expect( testObj.$count( "buildUrlEndpoint" ) ).tobe( 1 ); + } ); + } ); + } + +} +