Prechádzať zdrojové kódy

Consolidated testing certificates

Signed-off-by: Stan Janssen <stan.janssen@elaad.nl>
Stan Janssen 3 rokov pred
rodič
commit
e9eac00a52

+ 2 - 0
certificates/generate_certificates.sh

@@ -1,3 +1,5 @@
+set -e
+
 echo "Please make sure the line RANDFILE = ... is commented out in your /etc/ssl/openssl.conf."
 
 echo "Generating the CA key"

+ 20 - 2
openleadr/client.py

@@ -172,7 +172,7 @@ class OpenADRClient:
                    reading_type=enums.READING_TYPE.DIRECT_READ,
                    report_type=enums.REPORT_TYPE.READING, sampling_rate=None, data_source=None,
                    scale="none", unit=None, power_ac=True, power_hertz=50, power_voltage=230,
-                   market_context=None):
+                   market_context=None, end_device_asset_mrid=None, report_data_source=None):
         """
         Add a new reporting capability to the client.
 
@@ -201,7 +201,15 @@ class OpenADRClient:
         :param str report_type: An OpenADR report type (found in openleadr.enums.REPORT_TYPE)
         :param datetime.timedelta sampling_rate: The sampling rate for the measurement.
         :param str unit: The unit for this measurement.
-
+        :param boolean power_ac: Whether the power is AC (True) or DC (False).
+                                 Only required when supplying a power-related measurement.
+        :param int power_hertz: Grid frequency of the power.
+                                Only required when supplying a power-related measurement.
+        :param int power_voltage: Voltage of the power.
+                                  Only required when supplying a power-related measurement.
+        :param str market_context: The Market Context that this report belongs to.
+        :param str end_device_asset_mrid: the Meter ID for the end device that is measured by this report.
+        :param report_data_source: A (list of) target(s) that this report is related to.
         """
 
         # Verify input
@@ -673,6 +681,11 @@ class OpenADRClient:
         if event['event_descriptor']['event_id'] in self.events:
             return self.responded_events['event_id']
 
+    async def on_register_report(self, report):
+        """
+        Placeholder for the on_register_report handler.
+        """
+
     ###########################################################################
     #                                                                         #
     #                                  LOW LEVEL                              #
@@ -800,6 +813,11 @@ class OpenADRClient:
                 for report_request in response_payload['report_requests']:
                     await self.create_report(report_request)
 
+        elif response_type == 'oadrRegisterReport':
+            if 'reports' in response_payload and len(response_payload['reports']) > 0:
+                for report in response_payload['reports']:
+                    await self.register_report(report)
+
         else:
             logger.warning(f"No handler implemented for incoming message "
                            f"of type {response_type}, ignoring.")

+ 0 - 32
test/cert.pem

@@ -1,32 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIFiTCCA3GgAwIBAgIUIIpr283UlljB8eqbykYRd/j75h4wDQYJKoZIhvcNAQEL
-BQAwVDELMAkGA1UEBhMCTkwxEzARBgNVBAgMCkdlbGRlcmxhbmQxDzANBgNVBAcM
-BkFybmhlbTEfMB0GA1UECgwWT3BlbkxFQURSIE9yZ2FuaXphdGlvbjAeFw0yMDA5
-MDkwNzU3MTRaFw0zMDA5MDcwNzU3MTRaMFQxCzAJBgNVBAYTAk5MMRMwEQYDVQQI
-DApHZWxkZXJsYW5kMQ8wDQYDVQQHDAZBcm5oZW0xHzAdBgNVBAoMFk9wZW5MRUFE
-UiBPcmdhbml6YXRpb24wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDM
-pEJj7sovh0EAQdCJW85cSPJ0UQZ137wGAP05sVjgh8k9kfyIbrsnUnhvByI/NHAQ
-nyXtJP8rvvakgsNj/YizzgYO8n6s69NGi0mnZCTV9gjUlt2HZ8v/UTkL4otEhXSw
-3r/B2vrTqfhNkJI/b9cJAaQGwLLc5TCC+NzukXUl4BtBv5js1Z29mnvsGHgvxzoA
-jcWBY52KHvAZvt0GsShyOje2E71gch/tMfKipqlNB2Cbmq9gFnGyJTJncbHoGMxr
-7is5v5bzJOXuJj/Eztbcj2rH31ltV1jBbAdWfcKGbMmTPNZTOvsDO6L2M0U5fiFR
-24fSfACd9IvvbiBgDIo9dMxdC2hJ3MwqJKK6L03ungDiXJyCtQqwgYtlSpfjI0tz
-kPs29pYtBqAdQEMOrdMcNn+94O6Axylr1fjTg3d41w6X7IOhfKxyG285fk6ad4DH
-3RrRRdjsO6LZUgSKzpxKGlGpcRKMgpMI360L44NJEh598W2whRjcozvNicqlWGze
-eu+zEeeFIta+9vfFxpI0aLLBUq3JZm2cdKSBfHGyBBV9ids0CfeIBFrwB0vVsF22
-UHg3t7LTfLaP4xlrRvlITzy2l0eJhDNPIWSXXA9Hl2+XQoYf4iYwY628loXPeyAd
-nXmMse0KbSJtUiuDqQOLuyF8aty4hNLzJ0K5w+OPyQIDAQABo1MwUTAdBgNVHQ4E
-FgQUjHzJIuGIAx5lr1bVjefd1Xi1/tYwHwYDVR0jBBgwFoAUjHzJIuGIAx5lr1bV
-jefd1Xi1/tYwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAgEAcCGc
-jjqT1LaJijJAY/EQxA/baqS3/d9dTH1A7khPTm9dtFAg1Nlrovhul4pi+yK9F4np
-iGgHsYx2IafuvTZ4DlcimtMfNRuH11BZsVQoBqJH3QPDa2s99zUnGN0XRYDgsh50
-9li9YW1PsNfcVX0YTkOMUgF9vEqiSnvpNnfdINEA/MJQysrERkfdzDO8pETQ0/cb
-VPpYStu4mJ1MQMQKuieYGtOkvzFWFT1aeQg1UMUATfBbWCC7vkbupMzhLiYFh+ZT
-ny17vhUMFMAr7Kt6cil+CavK9x88NRk4i1Jop1c/Nz6OlB67q4/Zhiz7NUKAUp0v
-iyWnelpg/jQ2tfFp6ThaIGX4Jgz1oa/w6QCCUCSwqZeuXl1sLZ8NyNsssGPLUuDt
-mbfmpVMoBleQB/J94P6QJtr9yCBWokUNrZGugmnrGuLR/FSBmq9C/hiuVnwM1uCM
-8yPPkjaD2pewXDzarrg9dEFd1G4WSv+YLj9uhuVILnS1GKzHBJtslYL7aVXvMlcx
-ER4rrcWunQBZAyWg8FqA+RlX30mDiHIDsZBl2/1t1yKCifhnMIgEx0kKk4KrD4CR
-f22dfslN4950FRhpA51rBdxKcJnw8XziucG8VGKnTONCF30IPDeT1eHj/th2m28S
-/Y2BqiYt4MxrrOmaEAaqupRYzH6FhG+jbgGIyVA=
------END CERTIFICATE-----

+ 4 - 4
test/integration_tests/test_client_registration.py

@@ -31,8 +31,8 @@ VEN_NAME = 'myven'
 VEN_ID = '1234abcd'
 VTN_ID = "TestVTN"
 
-CERTFILE = os.path.join(os.path.dirname(os.path.dirname(__file__)), "cert.pem")
-KEYFILE =  os.path.join(os.path.dirname(os.path.dirname(__file__)), "key.pem")
+CERTFILE = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'certificates', 'dummy_ven.crt')
+KEYFILE =  os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'certificates', 'dummy_ven.key')
 
 
 async def _on_create_party_registration(payload):
@@ -49,7 +49,7 @@ async def start_server():
 
 @pytest.fixture
 async def start_server_with_signatures():
-    server = OpenADRServer(vtn_id=VTN_ID, cert=CERTFILE, key=KEYFILE, passphrase='openadr', fingerprint_lookup=fingerprint_lookup, http_port=SERVER_PORT)
+    server = OpenADRServer(vtn_id=VTN_ID, cert=CERTFILE, key=KEYFILE, fingerprint_lookup=fingerprint_lookup, http_port=SERVER_PORT)
     server.add_handler('on_create_party_registration', _on_create_party_registration)
     await server.run_async()
     yield
@@ -87,7 +87,7 @@ async def test_create_party_registration_with_signatures(start_server_with_signa
         cert = file.read()
     client = OpenADRClient(ven_name=VEN_NAME,
                            vtn_url=f"http://localhost:{SERVER_PORT}/OpenADR2/Simple/2.0b",
-                           cert=CERTFILE, key=KEYFILE, passphrase='openadr', vtn_fingerprint=certificate_fingerprint(cert))
+                           cert=CERTFILE, key=KEYFILE, vtn_fingerprint=certificate_fingerprint(cert))
 
     response_type, response_payload = await client.create_party_registration()
     assert response_type == 'oadrCreatedPartyRegistration'

+ 0 - 54
test/key.pem

@@ -1,54 +0,0 @@
------BEGIN ENCRYPTED PRIVATE KEY-----
-MIIJnDBOBgkqhkiG9w0BBQ0wQTApBgkqhkiG9w0BBQwwHAQIx0KwpLX3E6ECAggA
-MAwGCCqGSIb3DQIJBQAwFAYIKoZIhvcNAwcECJ//ErIFZQJJBIIJSKJgQttwaFke
-9rBpQLmpQgWVYt9XTcOmJNXnOAZdrRv0JzOoo2LYR+ejDSWFJyXznL3TLr4vywkn
-YvPM1QF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 4 - 5
test/test_signatures.py

@@ -23,14 +23,14 @@ from datetime import datetime, timedelta, timezone
 from lxml import etree
 import os
 
-with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'cert.pem'), 'rb') as file:
+with open(os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), 'certificates', 'dummy_ven.crt'), 'rb') as file:
     TEST_CERT = file.read()
-with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'key.pem'), 'rb') as file:
+with open(os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), 'certificates', 'dummy_ven.key'), 'rb') as file:
     TEST_KEY = file.read()
 TEST_KEY_PASSWORD = 'openadr'
 
 def test_message_validation():
-    msg = create_message('oadrPoll', ven_id='123', cert=TEST_CERT, key=TEST_KEY, passphrase='openadr')
+    msg = create_message('oadrPoll', ven_id='123', cert=TEST_CERT, key=TEST_KEY)
     tree = etree.fromstring(msg.encode('utf-8'))
     validate_xml_signature(tree)
     parsed_type, parsed_message = parse_message(msg)
@@ -80,8 +80,7 @@ def test_message_validation_complex():
                          response={'request_id': 123, 'response_code': 200, 'response_description': 'OK'},
                          events=[event],
                          cert=TEST_CERT,
-                         key=TEST_KEY,
-                         passphrase='openadr')
+                         key=TEST_KEY)
     tree = etree.fromstring(msg.encode('utf-8'))
     validate_xml_signature(tree)
     parsed_type, parsed_msg = parse_message(msg)