Skip to content

Commit

Permalink
Fix for dell#370
Browse files Browse the repository at this point in the history
  • Loading branch information
ABHISHEK-SINHA10 committed May 6, 2024
1 parent 0a566ca commit 9a43e65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions plugins/modules/ome_application_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ def get_san(subject_alternative_names):
return subject_alternative_names.replace(" ", "")


def format_csr_string(csr_string):
# Remove the header and footer
csr_string = csr_string.replace("-----BEGIN CERTIFICATE REQUEST-----", "")
csr_string = csr_string.replace("-----END CERTIFICATE REQUEST-----", "")
csr_string = csr_string.replace("\n", "")

# Format the remaining string with proper line breaks
formatted_csr = '\n'.join([csr_string[i:i + 64] for i in range(0, len(csr_string), 64)])

# Add the header and footer back
formatted_csr = "-----BEGIN CERTIFICATE REQUEST-----\n" + formatted_csr + "\n-----END CERTIFICATE REQUEST-----"

return formatted_csr


def main():
specs = {
"command": {"type": "str", "required": False,
Expand Down Expand Up @@ -228,6 +243,8 @@ def main():
resp = rest_obj.invoke_request(method, uri, headers=headers, data=payload, dump=dump)
if resp.success:
if command == "generate_csr":
formated_csr = format_csr_string(resp.json_data["CertificateData"])
resp.json_data["CertificateData"] = formated_csr
module.exit_json(msg="Successfully generated certificate signing request.",
csr_status=resp.json_data)
module.exit_json(msg="Successfully uploaded application certificate.", changed=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def test_upload_csr_success(self, mocker, ome_default_args, ome_connection_mock_

def test_generate_csr(self, mocker, ome_default_args, ome_connection_mock_for_application_certificate,
ome_response_mock):
csr_json = {"CertificateData": "--BEGIN-REQUEST--"}
csr_data = "-----BEGIN CERTIFICATE REQUEST-----MIIFMDCCAxgCAQAwgbAxCzAJBgNVBAYTAlVTMREwDwYDVQQIDAhWaXJnaW5pYTES-----END CERTIFICATE REQUEST-----"
csr_json = {"CertificateData": csr_data}
payload = {"DistinguishedName": "hostname.com", "DepartmentName": "Remote Access Group",
"BusinessName": "Dell Inc.", "Locality": "Round Rock", "State": "Texas",
"Country": "US", "Email": EMAIL_ADDRESS, "subject_alternative_names": "XX.XX.XX.XX"}
Expand All @@ -121,4 +122,5 @@ def test_generate_csr(self, mocker, ome_default_args, ome_connection_mock_for_ap
ome_response_mock.json_data = csr_json
result = self.execute_module(ome_default_args)
assert result['msg'] == "Successfully generated certificate signing request."
assert result['csr_status'] == {'CertificateData': '--BEGIN-REQUEST--'}
data = '''-----BEGIN CERTIFICATE REQUEST-----\nMIIFMDCCAxgCAQAwgbAxCzAJBgNVBAYTAlVTMREwDwYDVQQIDAhWaXJnaW5pYTES\n-----END CERTIFICATE REQUEST-----'''
assert result['csr_status']['CertificateData'] == data

0 comments on commit 9a43e65

Please sign in to comment.