Beispiel #1
0
def test_hash_ha1():
    from wazo_router_confd.services import password

    result = password.hash_ha1(None, None, None)
    assert result is None
    #
    result = password.hash_ha1("username", "realm", "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
Beispiel #3
0
def test_kamailio_auth_ip_address_username_fails(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,
        ip_address="10.0.0.1",
        username='******',
        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": "******",
            "password": "******",
        },
    )
    assert response.status_code == 200
    assert response.json() == {
        "success": False,
        "tenant_uuid": None,
        "carrier_trunk_id": None,
        "ipbx_id": None,
        "domain": None,
        "username": None,
        "password_ha1": None,
    }
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