Skip to content

Commit

Permalink
Fix unit tests for nfse
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed May 11, 2023
1 parent 6ea3f00 commit 03af353
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pytrustnfe/certificado.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def save_pfx(self):


def extract_cert_and_key_from_pfx(pfx, password):
pfx = crypto.load_pkcs12(pfx, password)
pfx = crypto.load_pkcs12(pfx, password.encode())
# PEM formatted private key
key = crypto.dump_privatekey(crypto.FILETYPE_PEM, pfx.get_privatekey())
# PEM formatted certificate
Expand Down
6 changes: 3 additions & 3 deletions pytrustnfe/nfse/paulistana/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@


def sign_tag(certificado, **kwargs):
pkcs12 = crypto.load_pkcs12(certificado.pfx, certificado.password)
pkcs12 = crypto.load_pkcs12(certificado.pfx, certificado.password.encode())
key = pkcs12.get_privatekey()
if "nfse" in kwargs:
for item in kwargs["nfse"]["lista_rps"]:
signed = crypto.sign(key, item["assinatura"], "SHA1")
signed = crypto.sign(key, item["assinatura"].encode(), "SHA1")
item["assinatura"] = b64encode(signed).decode()
if "cancelamento" in kwargs:
signed = crypto.sign(key, kwargs["cancelamento"]["assinatura"], "SHA1")
signed = crypto.sign(key, kwargs["cancelamento"]["assinatura"].encode(), "SHA1")
kwargs["cancelamento"]["assinatura"] = b64encode(signed).decode()


Expand Down
3 changes: 2 additions & 1 deletion tests/XMLs/paulistana_signature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ mh66HMVzAfE8vRNwW5b7m6nWS1SiHBon7/Mqsw4MIq3SC+J/fTbKpqwyfAuH2YZl
AiQuQc85fyllAMLh2WrA7JgOLR/5tF3kLtpbHdECAwEAATANBgkqhkiG9w0BAQUF
AAOBgQArdh+RyT6VxKGsXk1zhHsgwXfToe6GpTF4W8PHI1+T0WIsNForDhvst6nm
QtgAhuZM9rxpOJuNKc+pM29EixpAiZZiRMCSWEItNyEVdUIi+YnKBcAHd88TwO86
d126MWQ2O8cu5W1VoDp7hYBYKOnLbYi11/StO+0rzK+oPYAvIw==</X509Certificate>
d126MWQ2O8cu5W1VoDp7hYBYKOnLbYi11/StO+0rzK+oPYAvIw==
</X509Certificate>
</X509Data>
</KeyInfo>
</Signature></PedidoEnvioLoteRPS>
2 changes: 1 addition & 1 deletion tests/test_nfse_paulistana.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8

import mock
from unittest import mock
import os.path
import unittest
from pytrustnfe.certificado import Certificado
Expand Down

0 comments on commit 03af353

Please sign in to comment.