Ejemplo n.º 1
0
def test_extension_object():
    obj = ua.UserNameIdentityToken()
    obj.UserName = "******"
    obj.Password = b"pass"
    obj2 = extensionobject_from_binary(ua.utils.Buffer(extensionobject_to_binary(obj)))
    assert type(obj) == type(obj2)
    assert obj.UserName == obj2.UserName
    assert obj.Password == obj2.Password
    v1 = ua.Variant(obj)
    v2 = variant_from_binary(ua.utils.Buffer(variant_to_binary(v1)))
    assert type(v1) == type(v2)
    assert v1.VariantType == v2.VariantType
Ejemplo n.º 2
0
 def _add_user_auth(self, params, username: str, password: str):
     params.UserIdentityToken = ua.UserNameIdentityToken()
     params.UserIdentityToken.UserName = username
     policy_uri = self.server_policy_uri(ua.UserTokenType.UserName)
     if not policy_uri or policy_uri == security_policies.POLICY_NONE_URI:
         # see specs part 4, 7.36.3: if the token is NOT encrypted,
         # then the password only contains UTF-8 encoded password
         # and EncryptionAlgorithm is null
         if self._password:
             _logger.warning("Sending plain-text password")
             params.UserIdentityToken.Password = password.encode("utf8")
         params.UserIdentityToken.EncryptionAlgorithm = None
     elif self._password:
         data, uri = self._encrypt_password(password, policy_uri)
         params.UserIdentityToken.Password = data
         params.UserIdentityToken.EncryptionAlgorithm = uri
     params.UserIdentityToken.PolicyId = self.server_policy_id(ua.UserTokenType.UserName, "username_basic256")