def test_hash(): from wazo_router_confd.services import password result = password.hash(None) assert result is None # result = password.hash("password") assert result is not None
def update_ipbx(db: Session, principal: Principal, ipbx_id: int, ipbx: schema.IPBXUpdate) -> IPBX: db_ipbx = get_ipbx(db, principal, ipbx_id) if db_ipbx is not None: db_ipbx.tenant_uuid = (ipbx.tenant_uuid if ipbx.tenant_uuid is not None else db_ipbx.tenant_uuid) db_ipbx.domain_id = (ipbx.domain_id if ipbx.domain_id is not None else db_ipbx.domain_id) db_ipbx.normalization_profile_id = ( ipbx.normalization_profile_id if ipbx.normalization_profile_id is not None else db_ipbx.normalization_profile_id) db_ipbx.customer = (ipbx.customer if ipbx.customer is not None else db_ipbx.customer) db_ipbx.ip_fqdn = ipbx.ip_fqdn if ipbx.ip_fqdn is not None else db_ipbx.ip_fqdn db_ipbx.port = ipbx.port if ipbx.port is not None else db_ipbx.port db_ipbx.ip_address = (ipbx.ip_address if ipbx.ip_address is not None else db_ipbx.ip_address) db_ipbx.registered = (ipbx.registered if ipbx.registered is not None else db_ipbx.registered) db_ipbx.username = (ipbx.username if ipbx.username is not None else db_ipbx.username) if ipbx.password is not None: domain = db.query(Domain).filter( Domain.id == ipbx.domain_id).first() db_ipbx.password = password_service.hash(ipbx.password) db_ipbx.password_ha1 = password_service.hash_ha1( ipbx.username, domain.domain, ipbx.password) db_ipbx.realm = ipbx.realm if ipbx.realm is not None else db_ipbx.realm db.commit() db.refresh(db_ipbx) return db_ipbx
def create_carrier_trunk( db: Session, principal: Principal, carrier_trunk: schema.CarrierTrunkCreate ) -> CarrierTrunk: carrier_trunk.tenant_uuid = tenant_service.get_uuid( principal, db, carrier_trunk.tenant_uuid ) db_carrier_trunk = CarrierTrunk( tenant_uuid=carrier_trunk.tenant_uuid, carrier_id=carrier_trunk.carrier_id, name=carrier_trunk.name, normalization_profile_id=carrier_trunk.normalization_profile_id, sip_proxy=carrier_trunk.sip_proxy, sip_proxy_port=carrier_trunk.sip_proxy_port, ip_address=carrier_trunk.ip_address, registered=carrier_trunk.registered, auth_username=carrier_trunk.auth_username, auth_password=password_service.hash(carrier_trunk.auth_password), realm=carrier_trunk.realm, registrar_proxy=carrier_trunk.registrar_proxy, from_domain=carrier_trunk.from_domain, expire_seconds=carrier_trunk.expire_seconds, retry_seconds=carrier_trunk.retry_seconds, ) db.add(db_carrier_trunk) db.commit() db.refresh(db_carrier_trunk) return db_carrier_trunk
def test_kamailio_auth_username_domain(app_auth, client_auth_with_token): from wazo_router_confd.database import SessionLocal from wazo_router_confd.models.tenant import Tenant from wazo_router_confd.models.domain import Domain from wazo_router_confd.models.ipbx import IPBX from wazo_router_confd.services import password session = SessionLocal(bind=app_auth.engine) tenant = Tenant(name='fabio', uuid="ffffffff-ffff-4c1c-ad1c-ffffffffffff") domain = Domain(domain='testdomain.com', tenant=tenant) ipbx = IPBX( customer=1, ip_fqdn='mypbx.com', domain=domain, registered=True, username='******', password=password.hash('password'), password_ha1=password.hash_ha1('user', domain.domain, 'password'), tenant=tenant, ) session.add_all([tenant, domain, ipbx]) session.commit() # response = client_auth_with_token.post( "/1.0/kamailio/auth", json={ "source_ip": "10.0.0.1", "username": "******", "domain": "testdomain.com" }, ) assert response.status_code == 200 assert response.json() == { "success": True, "tenant_uuid": str(ipbx.tenant_uuid), "carrier_trunk_id": None, "ipbx_id": ipbx.id, "domain": domain.domain, "username": ipbx.username, "password_ha1": ipbx.password_ha1, }
def create_ipbx(db: Session, principal: Principal, ipbx: schema.IPBXCreate) -> IPBX: ipbx.tenant_uuid = tenant_service.get_uuid(principal, db, ipbx.tenant_uuid) domain = db.query(Domain).filter(Domain.id == ipbx.domain_id).first() db_ipbx = IPBX( tenant_uuid=ipbx.tenant_uuid, domain_id=ipbx.domain_id, normalization_profile_id=ipbx.normalization_profile_id, customer=ipbx.customer, ip_fqdn=ipbx.ip_fqdn, port=ipbx.port, ip_address=ipbx.ip_address, registered=ipbx.registered, username=ipbx.username, password=password_service.hash(ipbx.password), password_ha1=password_service.hash_ha1(ipbx.username, domain.domain, ipbx.password), realm=ipbx.realm, ) db.add(db_ipbx) db.commit() db.refresh(db_ipbx) return db_ipbx
def update_carrier_trunk( db: Session, principal: Principal, carrier_trunk_id: int, carrier_trunk: schema.CarrierTrunkUpdate, ) -> CarrierTrunk: db_carrier_trunk = get_carrier_trunk(db, principal, carrier_trunk_id) if db_carrier_trunk is not None: db_carrier_trunk.name = ( carrier_trunk.name if carrier_trunk.name is not None else db_carrier_trunk.name ) db_carrier_trunk.normalization_profile_id = ( carrier_trunk.normalization_profile_id if carrier_trunk.normalization_profile_id is not None else db_carrier_trunk.normalization_profile_id ) db_carrier_trunk.sip_proxy = ( carrier_trunk.sip_proxy if carrier_trunk.sip_proxy is not None else db_carrier_trunk.sip_proxy ) db_carrier_trunk.sip_proxy_port = ( carrier_trunk.sip_proxy_port if carrier_trunk.sip_proxy_port is not None else db_carrier_trunk.sip_proxy_port ) db_carrier_trunk.ip_address = ( carrier_trunk.ip_address if carrier_trunk.ip_address is not None else db_carrier_trunk.ip_address ) db_carrier_trunk.registered = ( carrier_trunk.registered if carrier_trunk.registered is not None else db_carrier_trunk.registered ) db_carrier_trunk.auth_username = ( carrier_trunk.auth_username if carrier_trunk.auth_username is not None else db_carrier_trunk.auth_username ) if carrier_trunk.auth_password is not None: db_carrier_trunk.auth_password = password_service.hash( carrier_trunk.auth_password ) db_carrier_trunk.realm = ( carrier_trunk.realm if carrier_trunk.realm is not None else db_carrier_trunk.realm ) db_carrier_trunk.registrar_proxy = ( carrier_trunk.registrar_proxy if carrier_trunk.registrar_proxy is not None else db_carrier_trunk.registrar_proxy ) db_carrier_trunk.from_domain = ( carrier_trunk.from_domain if carrier_trunk.from_domain is not None else db_carrier_trunk.from_domain ) db_carrier_trunk.expire_seconds = ( carrier_trunk.expire_seconds if carrier_trunk.expire_seconds is not None else db_carrier_trunk.expire_seconds ) db_carrier_trunk.retry_seconds = ( carrier_trunk.retry_seconds if carrier_trunk.retry_seconds is not None else db_carrier_trunk.retry_seconds ) db.commit() db.refresh(db_carrier_trunk) return db_carrier_trunk