Browse Source

add basic auth to the module

nico 8 years ago
parent
commit
2a38a1d2e3
2 changed files with 18 additions and 0 deletions
  1. 14 0
      neurons/uri/tests/uri_test_brain.yml
  2. 4 0
      neurons/uri/uri.py

+ 14 - 0
neurons/uri/tests/uri_test_brain.yml

@@ -24,6 +24,20 @@
           say_template:
             - "{{ content.id }}"
 
+  # POST with auth
+  - name: "test-post-url-with-auth"
+    signals:
+      - order: "test-post-url-with-auth"
+    neurons:
+      - uri:
+          url: "http://192.168.0.17:8000/app"
+          headers:
+            Content-Type: 'application/json'
+          method: POST
+          user: "admin"
+          password: "secret"
+          data_from_file: "neurons/uri/tests/data_post_test.json"
+
   # PUT
   - name: "test-put-url"
     signals:

+ 4 - 0
neurons/uri/uri.py

@@ -114,6 +114,10 @@ class Uri(NeuronModule):
         if self.data_from_file is not None:
             returned_parameters["data"] = self.data_from_file
 
+        if self.user is not None:
+            # this implicitly means that the password is set too, the check has been done in _is_parameters_ok
+            returned_parameters["auth"] = self.user, self.password
+
         logger.debug(self.neuron_name + " parameters: %s" % returned_parameters)
 
         return returned_parameters