You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2018/07/27 12:23:00 UTC

[sling-whiteboard] 03/03: Use function for auth

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit 46339c9d703ae44da8c407217b47ba153028e629
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Jul 27 14:22:21 2018 +0200

    Use function for auth
---
 .../src/test/java/sling/postservlet/createcontent/basic-auth.js     | 6 ++++++
 .../test/java/sling/postservlet/createcontent/createContent.feature | 5 +++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/literate-http-testing/karate/src/test/java/sling/postservlet/createcontent/basic-auth.js b/literate-http-testing/karate/src/test/java/sling/postservlet/createcontent/basic-auth.js
new file mode 100644
index 0000000..271725a
--- /dev/null
+++ b/literate-http-testing/karate/src/test/java/sling/postservlet/createcontent/basic-auth.js
@@ -0,0 +1,6 @@
+function(creds) {
+  var temp = creds.username + ':' + creds.password;
+  var Base64 = Java.type('java.util.Base64');
+  var encoded = Base64.getEncoder().encodeToString(temp.bytes);
+  return 'Basic ' + encoded;
+}
diff --git a/literate-http-testing/karate/src/test/java/sling/postservlet/createcontent/createContent.feature b/literate-http-testing/karate/src/test/java/sling/postservlet/createcontent/createContent.feature
index ab972c0..b0dc002 100644
--- a/literate-http-testing/karate/src/test/java/sling/postservlet/createcontent/createContent.feature
+++ b/literate-http-testing/karate/src/test/java/sling/postservlet/createcontent/createContent.feature
@@ -9,8 +9,9 @@ Background:
 
 * url 'http://localhost:8080'
 
-# Use admin:admin credentials for all requests
-* configure headers = { 'Authorization' : 'Basic YWRtaW46YWRtaW4=' }
+# Use admin credentials for all requests
+* def encodedAuth = call read('basic-auth.js') { username: 'admin', password: 'admin' }
+* configure headers = { 'Authorization' : #(encodedAuth) }
 
 # ------------------------------------------------------------------------
 Scenario: Check access to the Sling instance under test