Пример #1
0
def test_create_duplicated_carrier_trunk(app_auth, client_auth_with_token):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.tenant import Tenant

    tenant = Tenant(name="tenant", uuid="ffffffff-ffff-4c1c-ad1c-ffffffffffff")
    carrier = Carrier(name="carrier", tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='carrier_trunk1',
        tenant=tenant,
        carrier=carrier,
        sip_proxy='proxy.somedomain.com',
    )
    session = SessionLocal(bind=app_auth.engine)
    session.add_all([tenant, carrier, carrier_trunk])
    session.commit()
    #
    response = client_auth_with_token.post(
        "/1.0/carrier_trunks",
        json={
            "name": "carrier_trunk1",
            "tenant_uuid": str(tenant.uuid),
            "carrier_id": carrier.id,
            "sip_proxy": "proxy.somedomain.com",
        },
    )
    assert response.status_code == 409
def create_routing_rule(app_auth, tenant_uuid, suffix=1):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.domain import Domain
    from wazo_router_confd.models.tenant import Tenant
    from wazo_router_confd.models.ipbx import IPBX
    from wazo_router_confd.models.routing_group import RoutingGroup
    from wazo_router_confd.models.routing_rule import RoutingRule

    session = SessionLocal(bind=app_auth.engine)
    tenant = session.query(Tenant).filter(Tenant.uuid == tenant_uuid).first()
    if tenant is None:
        tenant = Tenant(name="tenant_{}".format(suffix), uuid=tenant_uuid)
        session.add(tenant)
    domain = Domain(domain='testdomain_{}.com'.format(suffix), tenant=tenant)
    ipbx = IPBX(
        tenant=tenant,
        domain=domain,
        customer=1,
        ip_fqdn='mypbx.com',
        registered=True,
        username='******',
        password='******',
    )
    carrier = Carrier(name='carrier_{}'.format(suffix), tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='carrier_trunk_{}'.format(suffix),
        carrier=carrier,
        sip_proxy='proxy.somedomain.com',
    )
    carrier_trunk_2 = CarrierTrunk(
        name='carrier_trunk_{}_bis'.format(suffix),
        carrier=carrier,
        sip_proxy='proxy.somedomain.com',
    )
    routing_rule = RoutingRule(
        prefix="39",
        carrier_trunk=carrier_trunk,
        ipbx=ipbx,
        did_regex=r'^(\+?1)?(8(00|44|55|66|77|88)[2-9]\d{6})$',
        route_type="pstn",
    )
    routing_group = RoutingGroup(tenant=tenant, routing_rule=routing_rule)

    session.add_all([
        tenant,
        domain,
        carrier,
        carrier_trunk,
        carrier_trunk_2,
        ipbx,
        routing_rule,
        routing_group,
    ])
    session.commit()

    session.flush()

    return routing_rule, ipbx, carrier_trunk, tenant, session
def test_kamailio_routing_did_with_no_matching_ipbx(app, client):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.domain import Domain
    from wazo_router_confd.models.tenant import Tenant
    from wazo_router_confd.models.ipbx import IPBX
    from wazo_router_confd.models.did import DID

    session = SessionLocal(bind=app.engine)
    tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34')
    domain = Domain(domain='testdomain.com', tenant=tenant)
    ipbx = IPBX(
        tenant=tenant,
        domain=domain,
        customer=1,
        ip_fqdn='mypbx.com',
        registered=True,
        username='******',
        password='******',
    )
    carrier = Carrier(name='carrier', tenant=tenant)
    carrier_trunk = CarrierTrunk(name='carrier_trunk1',
                                 carrier=carrier,
                                 sip_proxy='proxy.somedomain.com')
    did = DID(
        did_regex=r'^39[0-9]+$',
        did_prefix='39',
        tenant=tenant,
        ipbx=ipbx,
        carrier_trunk=carrier_trunk,
    )
    session.add_all([tenant, domain, ipbx, carrier, carrier_trunk, did])
    session.commit()
    #
    request_from_name = "From name"
    request_from_uri = "sip:[email protected]"
    request_from_tag = "from_tag"
    request_to_name = "to name"
    request_to_uri = "sip:[email protected]"
    request_to_tag = "to_tag"
    #
    response = client.post(
        "/1.0/kamailio/routing",
        json={
            "event": "sip-routing",
            "source_ip": "10.0.0.1",
            "source_port": 5060,
            "call_id": "call-id",
            "from_name": request_from_name,
            "from_uri": request_from_uri,
            "from_tag": request_from_tag,
            "to_uri": request_to_uri,
            "to_name": request_to_name,
            "to_tag": request_to_tag,
        },
    )
    assert response.status_code == 200
    assert response.json() == {"auth": None, "rtjson": {"success": False}}
Пример #4
0
def test_update_carrier_trunk(app_auth, client_auth_with_token):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.tenant import Tenant

    tenant = Tenant(name="tenant", uuid="ffffffff-ffff-4c1c-ad1c-ffffffffffff")
    carrier = Carrier(name="carrier", tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='carrier_trunk1',
        tenant=tenant,
        carrier=carrier,
        sip_proxy='proxy.somedomain.com',
        auth_username='******',
        auth_password='******',
    )
    session = SessionLocal(bind=app_auth.engine)
    session.add_all([tenant, carrier, carrier_trunk])
    session.commit()
    #
    response = client_auth_with_token.put(
        "/1.0/carrier_trunks/%s" % carrier_trunk.id,
        json={
            'name': 'updated_carrier_trunk1',
            "tenant_uuid": str(tenant.uuid),
            "carrier_id": carrier.id,
            "normalization_profile_id": None,
            "sip_proxy": "proxy.somedomain.com",
            "sip_proxy_port": 5061,
            "ip_address": "10.0.0.1",
            "registered": True,
            'auth_username': '******',
            'auth_password': '******',
            "realm": "somerealm.com",
            "registrar_proxy": "registrar-proxy.com",
            "from_domain": "gw.somedomain.com",
            "expire_seconds": 1800,
            "retry_seconds": 10,
        },
    )
    assert response.status_code == 200
    assert response.json() == {
        'id': carrier_trunk.id,
        'name': 'updated_carrier_trunk1',
        "tenant_uuid": str(tenant.uuid),
        "carrier_id": carrier.id,
        "normalization_profile_id": None,
        'sip_proxy': 'proxy.somedomain.com',
        "sip_proxy_port": 5061,
        "ip_address": "10.0.0.1",
        'auth_username': '******',
        'expire_seconds': 1800,
        'retry_seconds': 10,
        'from_domain': "gw.somedomain.com",
        'realm': "somerealm.com",
        'registered': True,
        'registrar_proxy': "registrar-proxy.com",
    }
def test_kamailio_cdr_failed_no_tenant(app, client):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.domain import Domain
    from wazo_router_confd.models.tenant import Tenant
    from wazo_router_confd.models.ipbx import IPBX
    from wazo_router_confd.models.did import DID

    session = SessionLocal(bind=app.engine)
    tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34')
    domain = Domain(domain='testdomain.com', tenant=tenant)
    ipbx = IPBX(
        tenant=tenant,
        domain=domain,
        customer=1,
        ip_fqdn='mypbx.com',
        registered=True,
        username='******',
        password='******',
    )
    carrier = Carrier(name='carrier', tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='carrier_trunk1', carrier=carrier, sip_proxy='proxy.somedomain.com'
    )
    did = DID(
        did_regex=r'^39[0-9]+$',
        did_prefix='39',
        tenant=tenant,
        ipbx=ipbx,
        carrier_trunk=carrier_trunk,
    )
    session.add_all([tenant, domain, ipbx, carrier, carrier_trunk, did])
    session.commit()
    #
    request_from_uri = "*****@*****.**"
    request_to_uri = "*****@*****.**"
    call_start = 1570752000
    duration = 60
    #
    response = client.post(
        "/1.0/kamailio/cdr",
        json={
            "tenant_uuid": "5ecdf9dd-36d3-4735-a5e8-99bd297bc325",
            "event": "sip-routing",
            "source_ip": "10.0.0.1",
            "source_port": 5060,
            "call_id": "call-id",
            "from_uri": request_from_uri,
            "to_uri": request_to_uri,
            "call_start": call_start,
            "duration": duration,
        },
    )

    assert response.status_code == 200
    assert response.json() == {"success": False, "cdr": None}
Пример #6
0
def create_carrier(
    db: Session, principal: Principal, carrier: schema.CarrierCreate
) -> Carrier:
    carrier.tenant_uuid = tenant_service.get_uuid(principal, db, carrier.tenant_uuid)
    db_carrier = Carrier(name=carrier.name, tenant_uuid=carrier.tenant_uuid)
    db.add(db_carrier)
    db.commit()
    db.refresh(db_carrier)
    return db_carrier
def test_get_carriers(app=None, client=None):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier

    session = SessionLocal(bind=app.engine)
    session.add(Carrier(name='carrier1', tenant_id=1))
    session.commit()
    #
    response = client.get("/carriers/")
    assert response.status_code == 200
    assert response.json() == [{'id': 1, 'name': 'carrier1', 'tenant_id': 1}]
def test_create_duplicated_carrier(app=None, client=None):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier

    session = SessionLocal(bind=app.engine)
    session.add(Carrier(name='carrier1', tenant_id=1))
    session.commit()
    #
    response = client.post("/carriers/",
                           json={
                               "name": "carrier1",
                               "tenant_id": 1
                           })
    assert response.status_code == 400
Пример #9
0
def test_create_duplicated_carrier(app, client):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.tenant import Tenant

    tenant = Tenant(name="tenant", uuid="3ab844af-8039-45d9-a3aa-bae6f298228f")
    carrier = Carrier(name='carrier1', tenant=tenant)
    session = SessionLocal(bind=app.engine)
    session.add_all([tenant, carrier])
    session.commit()
    #
    response = client.post(
        "/1.0/carriers", json={"name": "carrier1", "tenant_uuid": str(tenant.uuid)}
    )
    assert response.status_code == 409
def test_create_duplicated_carrier(app_auth, client_auth_with_token):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.tenant import Tenant

    tenant = Tenant(name="tenant", uuid="ffffffff-ffff-4c1c-ad1c-ffffffffffff")
    carrier = Carrier(name='carrier1', tenant=tenant)
    session = SessionLocal(bind=app_auth.engine)
    session.add_all([tenant, carrier])
    session.commit()
    #
    response = client_auth_with_token.post(
        "/1.0/carriers", json={"name": "carrier1", "tenant_uuid": str(tenant.uuid)}
    )
    assert response.status_code == 409
Пример #11
0
def test_create_carrier_trunk(app_auth, client_auth_with_token):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.tenant import Tenant

    tenant = Tenant(name="tenant", uuid="ffffffff-ffff-4c1c-ad1c-ffffffffffff")
    carrier = Carrier(name="carrier", tenant=tenant)
    session = SessionLocal(bind=app_auth.engine)
    session.add_all([tenant, carrier])
    session.commit()

    response = client_auth_with_token.post(
        "/1.0/carrier_trunks",
        json={
            "name": "carrier_trunk1",
            "tenant_uuid": str(tenant.uuid),
            "carrier_id": carrier.id,
            "sip_proxy": "proxy.somedomain.com",
            "ip_address": "10.0.0.1",
            "registered": True,
            "auth_username": "******",
            "auth_password": "******",
            "realm": "somerealm.com",
            "registrar_proxy": "registrar-proxy.com",
            "from_domain": "gw.somedomain.com",
            "expire_seconds": 1800,
            "retry_seconds": 10,
        },
    )
    assert response.status_code == 200
    assert response.json() == {
        "id": mock.ANY,
        "name": "carrier_trunk1",
        "tenant_uuid": str(tenant.uuid),
        "carrier_id": carrier.id,
        "normalization_profile_id": None,
        "sip_proxy": "proxy.somedomain.com",
        "sip_proxy_port": 5060,
        "ip_address": "10.0.0.1",
        "registered": True,
        "auth_username": "******",
        "realm": "somerealm.com",
        "registrar_proxy": "registrar-proxy.com",
        "from_domain": "gw.somedomain.com",
        "expire_seconds": 1800,
        "retry_seconds": 10,
    }
Пример #12
0
def test_get_carrier_trunk(app_auth, client_auth_with_token):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.tenant import Tenant

    tenant = Tenant(name="tenant", uuid="ffffffff-ffff-4c1c-ad1c-ffffffffffff")
    carrier = Carrier(name="carrier", tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='carrier_trunk1',
        tenant=tenant,
        carrier=carrier,
        sip_proxy='proxy.somedomain.com',
        registered=True,
        ip_address="10.0.0.1",
        auth_username='******',
        auth_password='******',
        realm='somerealm.com',
        registrar_proxy='registrar-proxy.com',
        from_domain='gw.somedomain.com',
        expire_seconds=1800,
        retry_seconds=10,
    )
    session = SessionLocal(bind=app_auth.engine)
    session.add_all([tenant, carrier, carrier_trunk])
    session.commit()
    #
    response = client_auth_with_token.get("/1.0/carrier_trunks/%d" % carrier_trunk.id)
    assert response.status_code == 200
    assert response.json() == {
        "id": carrier_trunk.id,
        "name": "carrier_trunk1",
        "tenant_uuid": str(tenant.uuid),
        "carrier_id": carrier.id,
        "normalization_profile_id": None,
        "sip_proxy": "proxy.somedomain.com",
        "sip_proxy_port": 5060,
        "ip_address": "10.0.0.1",
        "registered": True,
        "auth_username": "******",
        "realm": "somerealm.com",
        "registrar_proxy": "registrar-proxy.com",
        "from_domain": "gw.somedomain.com",
        "expire_seconds": 1800,
        "retry_seconds": 10,
    }
def test_get_dids(app, client):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.domain import Domain
    from wazo_router_confd.models.tenant import Tenant
    from wazo_router_confd.models.ipbx import IPBX
    from wazo_router_confd.models.did import DID

    session = SessionLocal(bind=app.engine)
    tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34')
    domain = Domain(domain='testdomain.com', tenant=tenant)
    ipbx = IPBX(
        tenant=tenant,
        domain=domain,
        customer=1,
        ip_fqdn='mypbx.com',
        registered=True,
        username='******',
        password='******',
    )
    carrier = Carrier(name='carrier', tenant=tenant)
    carrier_trunk = CarrierTrunk(name='carrier_trunk1',
                                 carrier=carrier,
                                 sip_proxy='proxy.somedomain.com')
    did = DID(
        did_regex=r'^(\+?1)?(8(00|44|55|66|77|88)[2-9]\d{6})$',
        tenant=tenant,
        ipbx=ipbx,
        carrier_trunk=carrier_trunk,
    )
    session.add_all([tenant, domain, ipbx, carrier, carrier_trunk, did])
    session.commit()
    #
    response = client.get("/1.0/dids")
    assert response.status_code == 200
    assert response.json() == {
        "items": [{
            "id": did.id,
            "did_regex": r"^(\+?1)?(8(00|44|55|66|77|88)[2-9]\d{6})$",
            "tenant_uuid": str(tenant.uuid),
            "ipbx_id": ipbx.id,
            "carrier_trunk_id": carrier_trunk.id,
        }]
    }
def test_get_carriers(app_auth, client_auth_with_token):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.tenant import Tenant

    tenant = Tenant(name="tenant", uuid="ffffffff-ffff-4c1c-ad1c-ffffffffffff")
    carrier = Carrier(name='carrier1', tenant=tenant)
    session = SessionLocal(bind=app_auth.engine)
    session.add_all([tenant, carrier])
    session.commit()
    #
    response = client_auth_with_token.get("/1.0/carriers")
    assert response.status_code == 200
    assert response.json() == {
        "items": [
            {'id': carrier.id, 'name': 'carrier1', 'tenant_uuid': str(tenant.uuid)}
        ]
    }
Пример #15
0
def test_get_carriers(app, client):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.tenant import Tenant

    tenant = Tenant(name="tenant", uuid="3ab844af-8039-45d9-a3aa-bae6f298228f")
    carrier = Carrier(name='carrier1', tenant=tenant)
    session = SessionLocal(bind=app.engine)
    session.add_all([tenant, carrier])
    session.commit()
    #
    response = client.get("/1.0/carriers")
    assert response.status_code == 200
    assert response.json() == {
        "items": [
            {'id': carrier.id, 'name': 'carrier1', 'tenant_uuid': str(tenant.uuid)}
        ]
    }
Пример #16
0
def test_get_carrier_trunks(app_auth, client_auth_with_token):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.tenant import Tenant

    tenant = Tenant(name="tenant", uuid="ffffffff-ffff-4c1c-ad1c-ffffffffffff")
    carrier = Carrier(name="carrier", tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='carrier_trunk1',
        tenant=tenant,
        carrier=carrier,
        sip_proxy='proxy.somedomain.com',
    )
    session = SessionLocal(bind=app_auth.engine)
    session.add_all([tenant, carrier, carrier_trunk])
    session.commit()
    #
    response = client_auth_with_token.get("/1.0/carrier_trunks")
    assert response.status_code == 200
    assert response.json() == {
        "items": [
            {
                'id': carrier_trunk.id,
                'name': 'carrier_trunk1',
                "tenant_uuid": str(tenant.uuid),
                "carrier_id": carrier.id,
                "normalization_profile_id": None,
                'sip_proxy': 'proxy.somedomain.com',
                "sip_proxy_port": 5060,
                "ip_address": None,
                'registered': False,
                'auth_username': None,
                'realm': None,
                'registrar_proxy': None,
                'from_domain': None,
                'expire_seconds': 3600,
                'retry_seconds': 30,
            }
        ]
    }
def test_kamailio_dbtext_uacreg(app, client):
    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.carrier import Carrier
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk

    session = SessionLocal(bind=app.engine)
    tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34')
    domain = Domain(domain='testdomain.com', tenant=tenant)
    carrier = Carrier(name='carrier1', tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='trunk1',
        carrier=carrier,
        sip_proxy='192.168.1.1',
        registered=True,
        auth_username='******',
        auth_password='******',
        realm='realm',
        registrar_proxy='registrar',
        from_domain='domain.com',
        expire_seconds=300,
        retry_seconds=10,
    )
    session.add_all([tenant, domain, carrier, carrier_trunk])
    session.commit()
    #
    response = client.get("/1.0/kamailio/dbtext/uacreg")
    assert response.status_code == 200
    assert response.json() == {
        "content": (
            "l_uuid(string) l_username(string) l_domain(string) "
            "r_username(string) r_domain(string) realm(string) "
            "auth_username(string) auth_password(string) auth_proxy(string) "
            "expires(int) flags(int) reg_delay(int)\n"
            "%s:username:domain.com:username:domain.com:realm:username:password:sip\\:registrar:300:16:0\n"
        )
        % carrier_trunk.id
    }
Пример #18
0
def test_delete_carrier_trunk(app, client):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.tenant import Tenant

    tenant = Tenant(name="tenant", uuid="3ab844af-8039-45d9-a3aa-bae6f298228f")
    carrier = Carrier(name="carrier", tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='carrier_trunk1',
        tenant=tenant,
        carrier=carrier,
        sip_proxy='proxy.somedomain.com',
        auth_username='******',
        auth_password='******',
    )
    session = SessionLocal(bind=app.engine)
    session.add_all([tenant, carrier, carrier_trunk])
    session.commit()
    #
    response = client.delete("/1.0/carrier_trunks/%s" % carrier_trunk.id)
    assert response.status_code == 200
    assert response.json() == {
        'id': carrier_trunk.id,
        'name': 'carrier_trunk1',
        "tenant_uuid": str(tenant.uuid),
        "carrier_id": carrier.id,
        "normalization_profile_id": None,
        'sip_proxy': 'proxy.somedomain.com',
        'sip_proxy_port': 5060,
        "ip_address": None,
        'auth_username': '******',
        'expire_seconds': 3600,
        'retry_seconds': 30,
        'from_domain': None,
        'realm': None,
        'registered': False,
        'registrar_proxy': None,
    }
Пример #19
0
def test_update_carrier(app, client):
    from wazo_router_confd.database import SessionLocal
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.tenant import Tenant

    tenant1 = Tenant(name="tenant1", uuid="3ab844af-8039-45d9-a3aa-bae6f298228f")
    tenant2 = Tenant(name="tenant2", uuid="458eb1a1-1769-4b7a-9970-45c5c9c2abe3")
    carrier = Carrier(name='carrier1', tenant=tenant1)
    session = SessionLocal(bind=app.engine)
    session.add_all([tenant1, tenant2, carrier])
    session.commit()
    #
    response = client.put(
        "/1.0/carriers/%d" % carrier.id,
        json={'name': 'updated_carrier', 'tenant_uuid': str(tenant2.uuid)},
    )
    assert response.status_code == 200
    assert response.json() == {
        'id': carrier.id,
        'name': 'updated_carrier',
        'tenant_uuid': str(tenant2.uuid),
    }
def test_kamailio_routing_outbound_with_single_ipbx_and_authenticated_carrier_trunk(
        app, client):
    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.carrier import Carrier
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.ipbx import IPBX

    session = SessionLocal(bind=app.engine)
    tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34')
    domain = Domain(domain='testdomain.com', tenant=tenant)
    carrier = Carrier(name='carrier1', tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='trunk1',
        carrier=carrier,
        sip_proxy='192.168.1.1',
        registered=True,
        auth_username='******',
        auth_password='******',
        realm='realm',
    )

    ipbx = IPBX(
        customer=1,
        ip_fqdn='10.0.0.1',
        domain=domain,
        registered=True,
        username='******',
        password='******',
        tenant=tenant,
    )
    session.add_all([tenant, domain, ipbx, carrier, carrier_trunk])
    session.commit()
    #
    request_from_name = "From name"
    request_from_uri = "sip:[email protected]"
    request_from_tag = "from_tag"
    request_to_name = "to name"
    request_to_uri = "sip:[email protected]"
    request_to_tag = "to_tag"
    #
    response = client.post(
        "/1.0/kamailio/routing",
        json={
            "event": "sip-routing",
            "source_ip": "10.0.0.1",
            "source_port": 5060,
            "call_id": "call-id",
            "from_name": request_from_name,
            "from_uri": request_from_uri,
            "from_tag": request_from_tag,
            "to_uri": request_to_uri,
            "to_name": request_to_name,
            "to_tag": request_to_tag,
        },
    )
    assert response.status_code == 200
    assert response.json() == {
        "auth": None,
        "rtjson": {
            "success":
            True,
            "version":
            "1.0",
            "routing":
            "serial",
            "routes": [{
                "dst_uri":
                "sip:%s:%s" %
                (carrier_trunk.sip_proxy, carrier_trunk.sip_proxy_port),
                "path":
                "",
                "socket":
                "",
                "headers": {
                    "from": {
                        "display": request_from_name,
                        "uri": request_from_uri
                    },
                    "to": {
                        "display": request_to_name,
                        "uri": request_to_uri
                    },
                    "extra":
                    "P-Asserted-Identity: <sip:" + request_from_name + "@" +
                    request_from_uri + ">\r\n",
                },
                "branch_flags":
                8,
                "fr_timer":
                5000,
                "fr_inv_timer":
                30000,
            }],
            "auth_username":
            "******",
            "auth_password":
            "******",
            "realm":
            "realm",
        },
    }
Пример #21
0
def test_kamailio_routing_outbound_with_single_ipbx(app, client):
    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.carrier import Carrier
    from wazo_router_confd.models.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.ipbx import IPBX
    from wazo_router_confd.models.normalization import NormalizationProfile

    session = SessionLocal(bind=app.engine)
    tenant = Tenant(name='fabio', uuid='5a6c0c40-b481-41bb-a41a-75d1cc25ff34')
    domain = Domain(domain='testdomain.com', tenant=tenant)
    normalization_profile = NormalizationProfile(
        tenant=tenant,
        name='Profile',
        country_code='39',
        area_code='040',
        intl_prefix='00',
        ld_prefix='',
        always_intl_prefix_plus=False,
        always_ld=False,
    )
    carrier = Carrier(name='carrier1', tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='trunk1',
        carrier=carrier,
        sip_proxy='192.168.1.1',
        normalization_profile=normalization_profile,
    )
    ipbx = IPBX(
        customer=1,
        ip_fqdn='10.0.0.1',
        domain=domain,
        registered=True,
        username='******',
        password='******',
        tenant=tenant,
        normalization_profile=normalization_profile,
    )
    session.add_all(
        [tenant, domain, normalization_profile, ipbx, carrier, carrier_trunk])
    session.commit()
    #
    request_from_name = "From name"
    request_from_uri = "sip:[email protected]"
    request_from_tag = "from_tag"
    request_to_name = "to name"
    request_to_uri = "sip:[email protected]"
    request_to_tag = "to_tag"
    #
    response = client.post(
        "/1.0/kamailio/routing",
        json={
            "event": "sip-routing",
            "source_ip": "10.0.0.1",
            "source_port": 5060,
            "call_id": "call-id",
            "from_name": request_from_name,
            "from_uri": request_from_uri,
            "from_tag": request_from_tag,
            "to_uri": request_to_uri,
            "to_name": request_to_name,
            "to_tag": request_to_tag,
        },
    )
    assert response.status_code == 200
    assert response.json() == {
        "auth": None,
        "rtjson": {
            "success":
            True,
            "version":
            "1.0",
            "routing":
            "serial",
            "routes": [{
                "dst_uri":
                "sip:%s:%s" %
                (carrier_trunk.sip_proxy, carrier_trunk.sip_proxy_port),
                "path":
                "",
                "socket":
                "",
                "headers": {
                    "from": {
                        "display": request_from_name,
                        "uri": request_from_uri
                    },
                    "to": {
                        "display": request_to_name,
                        "uri": request_to_uri
                    },
                    "extra": "",
                },
                "branch_flags":
                8,
                "fr_timer":
                5000,
                "fr_inv_timer":
                30000,
            }],
        },
    }
def test_kamailio_routing_domain_with_single_ipbx_and_auth(
        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.carrier_trunk import CarrierTrunk
    from wazo_router_confd.models.carrier import Carrier
    from wazo_router_confd.models.ipbx import IPBX
    from wazo_router_confd.models.normalization import NormalizationProfile

    session = SessionLocal(bind=app_auth.engine)
    tenant = Tenant(name='fabio', uuid='0839cb47-5d31-4b5e-8c5b-a2481f9e212a')
    domain = Domain(domain='testdomain.com', tenant=tenant)
    normalization_profile = NormalizationProfile(
        tenant=tenant,
        name='Profile',
        country_code='39',
        area_code='040',
        intl_prefix='00',
        ld_prefix='',
        always_intl_prefix_plus=False,
        always_ld=False,
    )
    ipbx = IPBX(
        customer=1,
        ip_fqdn='mypbx.com',
        ip_address='192.168.0.1',
        domain=domain,
        registered=True,
        username='******',
        password='******',
        normalization_profile=normalization_profile,
        tenant=tenant,
    )
    carrier = Carrier(name="carrier", tenant=tenant)
    carrier_trunk = CarrierTrunk(
        name='carrier_trunk1',
        tenant=tenant,
        carrier=carrier,
        normalization_profile=normalization_profile,
        sip_proxy='proxy.somedomain.com',
        ip_address="10.0.0.1",
    )
    session = SessionLocal(bind=app_auth.engine)
    session.add_all(
        [tenant, domain, normalization_profile, ipbx, carrier, carrier_trunk])
    session.commit()
    #
    request_from_name = "From name"
    request_from_uri = "sip:[email protected]"
    request_from_tag = "from_tag"
    request_to_name = "to name"
    request_to_uri = "sip:[email protected]"
    request_to_tag = "to_tag"
    #
    response = client_auth_with_token.post(
        "/1.0/kamailio/routing",
        json={
            "event": "sip-routing",
            "source_ip": "10.0.0.1",
            "source_port": 5060,
            "call_id": "call-id",
            "from_name": request_from_name,
            "from_uri": request_from_uri,
            "from_tag": request_from_tag,
            "to_uri": request_to_uri,
            "to_name": request_to_name,
            "to_tag": request_to_tag,
            "auth": True,
        },
    )
    assert response.status_code == 200
    assert response.json() == {
        "auth": {
            'tenant_uuid': str(tenant.uuid),
            'carrier_trunk_id': carrier_trunk.id,
            'ipbx_id': None,
            'domain': None,
            'username': None,
            'password_ha1': None,
            'success': True,
        },
        "rtjson": {
            "success":
            True,
            "version":
            "1.0",
            "routing":
            "serial",
            "routes": [{
                "dst_uri": "sip:%s:5060" % (ipbx.ip_fqdn),
                "path": "",
                "socket": "",
                "headers": {
                    "from": {
                        "display": request_from_name,
                        "uri": request_from_uri
                    },
                    "to": {
                        "display": request_to_name,
                        "uri": request_to_uri
                    },
                    "extra":
                    "P-Asserted-Identity: <sip:" + request_from_name + "@" +
                    request_from_uri + ">\r\n",
                },
                "branch_flags": 8,
                "fr_timer": 5000,
                "fr_inv_timer": 30000,
            }],
        },
    }