def test_approval_create_from_usb_device(cbcsdk_mock):
    """Test the create_from_usb_device function."""
    api = cbcsdk_mock.api
    usb = USBDevice(api, USBDEVICE_GET_RESP["id"], USBDEVICE_GET_RESP)
    approval = USBDeviceApproval.create_from_usb_device(usb)
    assert approval.serial_number == "4C531001331122115172"
    assert approval.vendor_id == "0x0781"
    assert approval.product_id == "0x5581"
コード例 #2
0
def test_usb_get_and_approve(cbcsdk_mock):
    """Tests getting a USB device by ID and approving it, checking the resulting USBDeviceApproval as well."""
    approval_saved = False
    get_calls = 0

    def getter_func(url, query_parameters, default):
        nonlocal approval_saved, get_calls
        get_calls = get_calls + 1
        if approval_saved:
            return USBDEVICE_GET_RESP_AFTER_APPROVE
        else:
            return USBDEVICE_GET_RESP_BEFORE_APPROVE

    def approval_call(url, body, **kwargs):
        assert len(body) == 1
        request = body[0]
        assert request["vendor_id"] == "0x0781"
        assert request['product_id'] == "0x5581"
        assert request['serial_number'] == "4C531001331122115172"
        assert request['approval_name'] == 'ApproveTest'
        assert request['notes'] == 'Approval notes'
        nonlocal approval_saved
        approval_saved = True
        return USBDEVICE_APPROVE_RESP

    cbcsdk_mock.mock_request("GET", "/device_control/v3/orgs/test/devices/808",
                             getter_func)
    cbcsdk_mock.mock_request("POST",
                             "/device_control/v3/orgs/test/approvals/_bulk",
                             approval_call)
    api = cbcsdk_mock.api
    usb = USBDevice(api, "808")
    assert usb.vendor_name == "SanDisk"
    assert usb.product_name == "Ultra"
    assert usb.status == 'UNAPPROVED'
    approval = usb.approve('ApproveTest', 'Approval notes')
    assert approval.id == "12703"
    assert approval.vendor_id == usb.vendor_id
    assert approval.product_id == usb.product_id
    assert approval.serial_number == usb.serial_number
    assert approval.approval_name == 'ApproveTest'
    assert approval.notes == 'Approval notes'
    assert usb.status == 'APPROVED'
    assert get_calls == 2
コード例 #3
0
def test_usb_get_and_get_endpoints(cbcsdk_mock):
    """Tests getting a USB device by ID and getting its endpoints."""
    cbcsdk_mock.mock_request("GET", "/device_control/v3/orgs/test/devices/774",
                             USBDEVICE_GET_RESP)
    cbcsdk_mock.mock_request(
        "GET", "/device_control/v3/orgs/test/devices/774/endpoints",
        USBDEVICE_GET_ENDPOINTS_RESP)
    api = cbcsdk_mock.api
    usb = USBDevice(api, "774")
    assert usb._model_unique_id == "774"
    assert usb.vendor_name == "SanDisk"
    assert usb.product_name == "Ultra"
    assert usb.status == "APPROVED"
    endpoints = usb.get_endpoints()
    assert len(endpoints) == 2
    assert endpoints[0]["id"] == "53"
    assert endpoints[0]["endpoint_id"] == 7590378
    assert endpoints[0]["policy_id"] == 6997287
    assert endpoints[1]["id"] == "50"
    assert endpoints[1]["endpoint_id"] == 7579317
    assert endpoints[1]["policy_id"] == 6997287
コード例 #4
0
def test_usb_query_products_seen(cbcsdk_mock):
    """Test the get_vendors_and_products_seen function."""
    cbcsdk_mock.mock_request("GET", "/device_control/v3/orgs/test/products",
                             USBDEVICE_GET_PRODUCTS_RESP)
    api = cbcsdk_mock.api
    results = USBDevice.get_vendors_and_products_seen(api)
    assert len(results) == 1
    assert results[0]['vendor_name'] == 'SanDisk'
    assert results[0]['devices_count'] == 5
    products = results[0]['products']
    assert len(products) == 5
    assert products[0]['product_name'] == 'U3 Cruzer Micro'
    assert products[1]['product_name'] == 'Cruzer Glide'
    assert products[2]['product_name'] == 'Ultra'
    assert products[3]['product_name'] == 'Ultra USB 3.0'
    assert products[4]['product_name'] == 'Cruzer Dial'