Skip to content

Commit

Permalink
extend ACL test case
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Oct 6, 2023
1 parent bb9bed9 commit 395762d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 32 deletions.
57 changes: 31 additions & 26 deletions source/fld/function.fld
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
<!-- StoreAddACL -->
<function>
<name>StoreAddACL</name>
<status>deprecated</status>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.StoreAddACL</class>
<description>Adds ACL to existing ACL for object or bucket. This function performs the same action as "S3AddACL". However, instead of providing the endpoint as a bucket/object definition, you supply it as a virtual filesystem path.</description>
<description>Adds ACL to existing ACL for object or bucket. This function operates identically to "S3AddACL", making it deprecated. The updated function offers greater flexibility in defining the endpoint.</description>
<argument>
<name>url</name>
<type>string</type>
Expand All @@ -38,21 +39,21 @@
<function>
<name>S3AddACL</name>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.S3AddACL</class>
<description>Adds ACL to existing ACL for object or bucket. This function performs the same action as "StoreAddACL". However, instead of providing the endpoint as a virtual filesystem path, you supply it as a bucket/object definition.</description>
<description>Adds ACL to existing ACL for object or bucket. You can provide the endpoint as a bucket/object defintion (S3AddACL(bucket:"mybucket",object:"myobject.txt",acl:data) ) or as a virtual filesystem path (S3AddACL(path:"s3://mybucket/myobject.txt",acl:data) ).</description>
<argument>
<name>bucketNameOrPath</name>
<alias>bucket,bucketName,path</alias>
<type>string</type>
<required>Yes</required>
<description>Name of the bucket of your object to read</description>
<description>This can be the bucketname or a virtual filesystem path for a file/directory (example "s3://mybucket/myobject.txt").</description>
</argument>
<argument>
<name>objectName</name>
<alias>object,path</alias>
<type>string</type>
<required>No</required>
<default></default>
<description>Name of the object (path) within the bucket of your object to read</description>
<description>Name of the object (path) within the bucket of your object to read. In case you have defined a bucket with the first argument.</description>
</argument>
<argument>
<name>aclObject</name>
Expand Down Expand Up @@ -96,8 +97,9 @@
<!-- StoreGetACL -->
<function>
<name>StoreGetACL</name>
<status>deprecated</status>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.StoreGetACL</class>
<description>Returns an array of structures, with each structure representing an ACL (Access Control List) grant. This function performs the same action as "S3GetACL". However, instead of providing the endpoint as a bucket/object definition, you supply it as a virtual filesystem path.</description>
<description>Returns an array of structures, with each structure representing an ACL (Access Control List) grant. This function operates identically to "S3GetACL", making it deprecated. The updated function offers greater flexibility in defining the endpoint.</description>
<argument>
<name>url</name>
<type>string</type>
Expand All @@ -113,21 +115,21 @@
<function>
<name>S3GetACL</name>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.S3GetACL</class>
<description>Returns an array of structures, with each structure representing an ACL (Access Control List) grant. This function performs the same action as "StoreGetACL". However, instead of providing the endpoint as a virtual filesystem path, you supply it as a bucket/object definition.</description>
<description>Returns an array of structures, with each structure representing an ACL (Access Control List) grant. You can provide the endpoint as a bucket/object defintion (S3GetACL(bucket:"mybucket",object:"myobject.txt") ) or as a virtual filesystem path (S3GetACL(path:"s3://mybucket/myobject.txt") ).</description>
<argument>
<name>bucketNameOrPath</name>
<alias>bucket,bucketName,path</alias>
<type>string</type>
<required>Yes</required>
<description>Name of the bucket of your object to read</description>
<description>This can be the bucketname or a virtual filesystem path for a file/directory (example "s3://mybucket/myobject.txt").</description>
</argument>
<argument>
<name>objectName</name>
<alias>object,path</alias>
<type>string</type>
<required>No</required>
<default></default>
<description>Name of the object (path) within the bucket of your object to read</description>
<description>Name of the object (path) within the bucket of your object to read. In case you have defined a bucket with the first argument.</description>
</argument>
<argument>
<name>accessKeyId</name>
Expand Down Expand Up @@ -164,8 +166,9 @@
<!-- StoreSetACL -->
<function>
<name>StoreSetACL</name>
<status>deprecated</status>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.StoreSetACL</class>
<description>Sets the ACL for object or bucket. This function performs the same action as "S3SetACL". However, instead of providing the endpoint as a bucket/object definition, you supply it as a virtual filesystem path.</description>
<description>Sets the ACL for object or bucket. This function operates identically to "S3SetACL", making it deprecated. The updated function offers greater flexibility in defining the endpoint.</description>
<argument>
<name>url</name>
<type>string</type>
Expand All @@ -188,21 +191,21 @@
<function>
<name>S3SetACL</name>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.S3SetACL</class>
<description>Sets ACL to existing ACL for object or bucket. This function performs the same action as "StoreSetACL". However, instead of providing the endpoint as a virtual filesystem path, you supply it as a bucket/object definition.</description>
<description>Sets ACL to existing ACL for object or bucket. You can provide the endpoint as a bucket/object defintion (S3SetACL(bucket:"mybucket",object:"myobject.txt",acl:data) ) or as a virtual filesystem path (S3SetACL(path:"s3://mybucket/myobject.txt",acl:data) ).</description>
<argument>
<name>bucketNameOrPath</name>
<alias>bucket,bucketName,path</alias>
<type>string</type>
<required>Yes</required>
<description>Name of the bucket of your object to read</description>
<description>This can be the bucketname or a virtual filesystem path for a file/directory (example "s3://mybucket/myobject.txt").</description>
</argument>
<argument>
<name>objectName</name>
<alias>object,path</alias>
<type>string</type>
<required>No</required>
<default></default>
<description>Name of the object (path) within the bucket of your object to read</description>
<description>Name of the object (path) within the bucket of your object to read. In case you have defined a bucket with the first argument.</description>
</argument>
<argument>
<name>aclObject</name>
Expand Down Expand Up @@ -248,9 +251,10 @@
<!-- StoreGetMetaData -->
<function>
<name>StoreGetMetaData</name>
<status>deprecated</status>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.StoreGetMetaData</class>
<introduced>5.0.0.000</introduced>
<description>Returns the metadata related to the object or bucket. This function performs the same action as "S3GetMetaData". However, instead of providing the endpoint as a bucket/object definition, you supply it as a virtual filesystem path.</description>
<description>Returns the metadata related to the object or bucket. This function operates identically to "S3GetMetaData", making it deprecated. The updated function offers greater flexibility in defining the endpoint.</description>
<argument>
<name>url</name>
<type>string</type>
Expand All @@ -266,21 +270,21 @@
<function>
<name>S3GetMetaData</name>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.S3GetMetaData</class>
<description>Returns the metadata related to the object or bucket. This function performs the same action as "StoreGetMetaData". However, instead of providing the endpoint as a virtual filesystem path, you supply it as a bucket/object definition.</description>
<description>Returns the metadata related to the object or bucket. You can provide the endpoint as a bucket/object defintion (S3GetMetaData(bucket:"mybucket",object:"myobject.txt") ) or as a virtual filesystem path (S3GetMetaData(path:"s3://mybucket/myobject.txt") ).</description>
<argument>
<name>bucketNameOrPath</name>
<alias>bucket,bucketName,path</alias>
<type>string</type>
<required>Yes</required>
<description>Name of the bucket of your object to read</description>
<description>This can be the bucketname or a virtual filesystem path for a file/directory (example "s3://mybucket/myobject.txt").</description>
</argument>
<argument>
<name>objectName</name>
<alias>object,path</alias>
<type>string</type>
<required>No</required>
<default></default>
<description>Name of the object (path) within the bucket of your object to read</description>
<description>Name of the object (path) within the bucket of your object to read. In case you have defined a bucket with the first argument.</description>
</argument>
<argument>
<name>accessKeyId</name>
Expand Down Expand Up @@ -318,9 +322,10 @@
<!-- StoreSetMetaData -->
<function>
<name>StoreSetMetaData</name>
<status>deprecated</status>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.StoreSetMetaData</class>
<introduced>5.0.0.000</introduced>
<description>Sets the metadata on bucket or object. This function performs the same action as "S3SetMetaData". However, instead of providing the endpoint as a bucket/object definition, you supply it as a virtual filesystem path.</description>
<description>Sets the metadata on bucket or object. This function operates identically to "S3SetMetaData", making it deprecated. The updated function offers greater flexibility in defining the endpoint.</description>
<argument>
<name>url</name>
<type>string</type>
Expand All @@ -342,21 +347,21 @@
<function>
<name>S3SetMetaData</name>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.S3SetMetaData</class>
<description>Sets the metadata on bucket or object. This function performs the same action as "StoreSetMetaData". However, instead of providing the endpoint as a virtual filesystem path, you supply it as a bucket/object definition.</description>
<description>Sets the metadata on bucket or object. You can provide the endpoint as a bucket/object defintion (S3SetMetaData(bucket:"mybucket",object:"myobject.txt",metadata:data) ) or as a virtual filesystem path (S3SetMetaData(path:"s3://mybucket/myobject.txt",metadata:data) ).</description>
<argument>
<name>bucketNameOrPath</name>
<alias>bucket,bucketName,path</alias>
<type>string</type>
<required>Yes</required>
<description>Name of the bucket of your object to read</description>
<description>This can be the bucketname or a virtual filesystem path for a file/directory (example "s3://mybucket/myobject.txt").</description>
</argument>
<argument>
<name>objectName</name>
<alias>object,path</alias>
<type>string</type>
<required>No</required>
<default></default>
<description>Name of the object (path) within the bucket of your object to read</description>
<description>Name of the object (path) within the bucket of your object to read. In case you have defined a bucket with the first argument.</description>
</argument>
<argument>
<name>metadata</name>
Expand Down Expand Up @@ -1063,20 +1068,20 @@
<function>
<name>S3GeneratePresignedURL</name>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.S3GeneratePresignedURL</class>
<description>Generates a presigned URL pointing to the object given</description>
<description>Generates a presigned URL pointing to the object given. You can provide the endpoint as a bucket/object defintion (S3AddACL(bucket:"mybucket",object:"myobject.txt") ) or as a virtual filesystem path (S3AddACL(path:"s3://mybucket/myobject.txt") ).</description>
<argument>
<name>bucketNameOrPath</name>
<alias>bucket,bucketName,path</alias>
<type>string</type>
<required>Yes</required>
<description>This can be the bucketname or simple the virtual filesystem point for the file (if object name is no defined)</description>
<description>This can be the bucketname or a virtual filesystem path for a file/directory (example "s3://mybucket/myobject.txt").</description>
</argument>
<argument>
<name>objectName</name>
<alias>object,path</alias>
<type>string</type>
<required>No</required>
<description>Name of the object (path) within the bucket of your object to read</description>
<description>Name of the object (path) within the bucket of your object to read. In case you have defined a bucket with the first argument.</description>
</argument>
<argument>
<name>expireDate</name>
Expand Down Expand Up @@ -1191,20 +1196,20 @@
<function>
<name>S3GenerateURI</name>
<class bundle-name="{bundle-name}" bundle-version="{bundle-version}">org.lucee.extension.resource.s3.function.S3GenerateURI</class>
<description>Generates a URI endpoint pointing to the object given</description>
<description>Generates a URI endpoint pointing to the object given. You can provide the endpoint as a bucket/object defintion (S3AddACL(bucket:"mybucket",object:"myobject.txt") ) or as a virtual filesystem path (S3AddACL(path:"s3://mybucket/myobject.txt") ).</description>
<argument>
<name>bucketNameOrPath</name>
<alias>bucket,bucketName,path</alias>
<type>string</type>
<required>Yes</required>
<description>This can be the bucketname or simple the virtual filesystem point for the file (if object name is no defined)</description>
<description>This can be the bucketname or a virtual filesystem path for a file/directory (example "s3://mybucket/myobject.txt").</description>
</argument>
<argument>
<name>objectName</name>
<alias>object,path</alias>
<type>string</type>
<required>No</required>
<description>Name of the object (path) within the bucket of your object you want to grant access to</description>
<description>Name of the object (path) within the bucket of your object to read. In case you have defined a bucket with the first argument.</description>
</argument>
<argument>
<name>type</name>
Expand Down
52 changes: 46 additions & 6 deletions tests/functions/S3Write.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,75 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" {


private function testit(cred) {

var file=expandPath("{temp-directory}/test-s3write.txt");
fileWrite(file, "Susi Sorglos");


try {
// create variables
var bucketName=cred.PREFIX&"-write"&listFirst(replace(server.lucee.version,".","","all"),"-");
var objectName="sub/test.txt";
var objectNameString="sub/string.txt";
var objectNameFile="sub/file.txt";

Util::deleteIfExists(cred,bucketName,objectName);
Util::deleteIfExists(cred,bucketName,objectNameString);
Util::deleteIfExists(cred,bucketName,objectNameFile);


// create source bucket
// create string source
if(!S3Exists(
bucketName:bucketName, objectName:objectName,
bucketName:bucketName, objectName:objectNameString,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST))) {
S3Write(
value:"Susi Sorglos",
bucketName:bucketName, objectName:objectName,
bucketName:bucketName, objectName:objectNameString,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST));
}

// create file source
if(!S3Exists(
bucketName:bucketName, objectName:objectNameFile,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST))) {
S3Write(
value:fileOpen(file),
bucketName:bucketName, objectName:objectNameFile,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST));
}

// existing bucket
assertTrue(
S3Exists(
bucketName:bucketName,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST))
);

// existing bucket/object
assertTrue(
S3Exists(
bucketName:bucketName, objectName:objectName,
bucketName:bucketName, objectName:objectNameString,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST))
);
// existing bucket/object
assertTrue(
S3Exists(
bucketName:bucketName, objectName:objectNameFile,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST))
);

assertEqual(
"Susi Sorglos",
S3Read(
bucketName:bucketName, objectName:objectNameString,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST))
);

assertEqual(
"Susi Sorglos",
S3Read(
bucketName:bucketName, objectName:objectNameFile,
accessKeyId:cred.ACCESS_KEY_ID, secretAccessKey:cred.SECRET_KEY, host:(isNull(cred.HOST)?nullvalue():cred.HOST))
);


}
catch(e) {
Expand Down

0 comments on commit 395762d

Please sign in to comment.