Repository: fetzerch/kasserver

Issue:
Switch from 'sha1' to 'plain' authentication method
The following E-Mail from All-Inkl support reached me today:

> Our system has detected that you are using the KAS API, which means that your custom scripts gain access to several features of the technical administration panel (KAS). So please forward the following information to the developer of those custom scripts as appropriate.
> 
> The authentication method "sha1" which is used by your custom scripts is deprecated and support for this authentication method will be gradually discontinued starting December 2022. In order to further use your custom scripts, an adjustment is necessary in the following accounts:
> 
> account : date of last sha1 authentication
> XXXXXXXX : 2022-08-01 22:19:25
> 
> Here's an example of how such a script code currently looks like: 
> 
> ```php
> $auth=array(
>  'kas_login' => 'XXXXXXXX',
>  'kas_auth_type' => 'sha1',
>  'kas_auth_data' => sha1('myPassword')
> )
> ```
> 
> Please alter your scripts in a way so that they use the new authentication method "plain" instead. An example how it should look afterwards: 
> 
> ```php
> $auth=array(
>  'kas_login' => 'XXXXXXXX',
>  'kas_auth_type' => 'plain',
>  'kas_auth_data' => 'myPassword'
> )
> ```
>
> You can find a full documentation of the KAS API under: 
> 
> http://kasapi.kasserver.com/dokumentation/phpdoc/

Discussion:
coveralls: ## Pull Request Test Coverage Report for [Build 2792750342](https://coveralls.io/builds/51399943)

* **2** of **2**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage remained the same at **100.0%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/51399943/badge)](https://coveralls.io/builds/51399943) |
| :-- | --: |
| Change from base [Build 2792727803](https://coveralls.io/builds/51399873): |  0.0% |
| Covered Lines: | 160 |
| Relevant Lines: | 160 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/kasserver/__init__.py b/kasserver/__init__.py
index 7f1364a..86d55c5 100644
--- a/kasserver/__init__.py
+++ b/kasserver/__init__.py
@@ -51,11 +51,8 @@ class KasServer:
         self._get_credentials()
 
     def _get_credentials(self):
-        def _sha1(string):
-            return None if not string else hashlib.sha1(string.encode()).hexdigest()
-
         self._username = os.environ.get("KASSERVER_USER", None)
-        self._auth_sha1 = _sha1(os.environ.get("KASSERVER_PASSWORD", None))
+        self._password = os.environ.get("KASSERVER_PASSWORD", None)
         if self._username:
             return
 
@@ -63,7 +60,7 @@ class KasServer:
         try:
             info = netrc.netrc().authenticators(server)
             self._username = info[0]
-            self._auth_sha1 = _sha1(info[2])
+            self._password = info[2]
         except (FileNotFoundError, netrc.NetrcParseError) as err:
             LOGGER.warning(
                 "Cannot load credentials for %s from .netrc: %s", server, err
@@ -72,8 +69,8 @@ class KasServer:
     def _request(self, request, params):
         request = {
             "KasUser": self._username,
-            "KasAuthType": "sha1",
-            "KasAuthData": self._auth_sha1,
+            "KasAuthType": "plain",
+            "KasAuthData": self._password,
             "KasRequestType": request,
             "KasRequestParams": params,
         }


Test patch:
diff --git a/tests/test_kasserver.py b/tests/test_kasserver.py
index ca18a2f..b7be822 100644
--- a/tests/test_kasserver.py
+++ b/tests/test_kasserver.py
@@ -36,7 +36,6 @@ LOGGER = logging.getLogger(__name__)
 
 USERNAME = "username"
 PASSWORD = "password"
-PASSWORD_SHA1 = "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8"
 
 # pylint: disable=protected-access
 # pylint: disable=attribute-defined-outside-init
@@ -56,7 +55,7 @@ class TestKasServerCredentials:
         netrc.side_effect = FileNotFoundError("")
         server = KasServer()
         assert server._username == USERNAME
-        assert server._auth_sha1 == PASSWORD_SHA1
+        assert server._password == PASSWORD
 
     @staticmethod
     @mock.patch.dict("os.environ", {})
@@ -66,7 +65,7 @@ class TestKasServerCredentials:
         netrc.return_value.authenticators.return_value = (USERNAME, "", PASSWORD)
         server = KasServer()
         assert server._username == USERNAME
-        assert server._auth_sha1 == PASSWORD_SHA1
+        assert server._password == PASSWORD
 
     @staticmethod
     @mock.patch.dict("os.environ", {})
@@ -76,7 +75,7 @@ class TestKasServerCredentials:
         netrc.side_effect = FileNotFoundError("")
         server = KasServer()
         assert not server._username
-        assert not server._auth_sha1
+        assert not server._password
 
 
 class TestKasServer:
@@ -186,8 +185,8 @@ class TestKasServer:
         kasserver._request(self.REQUEST_TYPE, self.REQUEST_PARAMS)
         request = {
             "KasUser": USERNAME,
-            "KasAuthType": "sha1",
-            "KasAuthData": PASSWORD_SHA1,
+            "KasAuthType": "plain",
+            "KasAuthData": PASSWORD,
             "KasRequestType": self.REQUEST_TYPE,
             "KasRequestParams": self.REQUEST_PARAMS,
         }