def test_authenticate(self, client: MDMClient, authenticate_request: str):
     """Basic test: Authenticate"""
     response: Response = client.put('/checkin',
                                     data=authenticate_request,
                                     content_type='text/xml')
     assert response.status_code != 410
     assert response.status_code == 200
 def test_tokenupdate(self, client: MDMClient, tokenupdate_request: str):
     """Test a client attempting to update its token after being unenrolled is forced to unenroll via code 410."""
     response: Response = client.put('/checkin',
                                     data=tokenupdate_request,
                                     content_type='text/xml')
     assert response.status_code != 200
     assert response.status_code == 410
 def test_checkout(self, client: MDMClient, checkout_request: str):
     """Test a CheckOut message"""
     response: Response = client.put('/checkin',
                                     data=checkout_request,
                                     content_type='text/xml')
     assert response.status_code != 410
     assert response.status_code == 200
Exemple #4
0
    def test_patch_hostname(self, client: MDMClient, session):
        """Patching the hostname should enqueue a Rename MDM command."""
        request_json = json.dumps({
            "data": {
                "type": "devices",
                "id": "1",
                "attributes": {
                    "hostname": "new name"
                }
            },
            "jsonapi": {
                "version": "1.0"
            }
        })

        response: Response = client.patch(
            "/api/v1/devices/1",
            data=request_json,
            content_type="application/vnd.api+json")
        assert response.status_code == 200

        try:
            cmd: Command = session.query(Command).filter(
                Command.request_type == 'Settings').one()
        except sqlalchemy.orm.exc.NoResultFound:
            assert False, "The API has created a new Settings Command to send to the device"

        device = json.loads(response.data)
        assert device['data']['attributes'][
            'hostname'] != "new name", "Device rename is still pending, API should reflect old name"
Exemple #5
0
 def test_device_information_response(self, client: MDMClient,
                                      device_information_response: str):
     response: Response = client.put('/mdm',
                                     data=device_information_response,
                                     content_type='text/xml')
     assert response.status_code != 410
     assert response.status_code == 200
Exemple #6
0
 def test_profile_list_response(self, client: MDMClient,
                                profile_list_response: str):
     response: Response = client.put('/mdm',
                                     data=profile_list_response,
                                     content_type='text/xml')
     assert response.status_code != 410
     assert response.status_code == 200
Exemple #7
0
    def test_certificate_list_response(self, client: MDMClient, certificate_list_response: str, session):
        response: Response = client.put('/mdm', data=certificate_list_response, content_type='text/xml')
        assert response.status_code != 410
        assert response.status_code == 200

        d = session.query(Device).filter(Device.udid == '00000000-1111-2222-3333-444455556666').one()
        ic = d.installed_certificates
        assert len(ic) == 2
Exemple #8
0
    def test_patch_device_name_reverted(self, client: MDMClient, session):
        """Patching the device name twice (change, then back to its original name)
           should remove the queued Settings command."""
        request_json = json.dumps({
            "data": {
                "type": "devices",
                "id": "1",
                "attributes": {
                    "device_name": "new name"
                }
            },
            "jsonapi": {
                "version": "1.0"
            }
        })

        request_two_json = json.dumps({
            "data": {
                "type": "devices",
                "id": "1",
                "attributes": {
                    "device_name": "commandment-mdmclient"
                }
            },
            "jsonapi": {
                "version": "1.0"
            }
        })

        response: Response = client.patch(
            "/api/v1/devices/1",
            data=request_json,
            content_type="application/vnd.api+json")
        assert response.status_code == 200

        second_response: Response = client.patch(
            "/api/v1/devices/1",
            data=request_two_json,
            content_type="application/vnd.api+json")
        assert second_response.status_code == 200

        settings_commands = session.query(Command).filter(
            Command.request_type == 'Settings').count()
        assert settings_commands == 1
    def test_available_os_updates_response(self, client: MDMClient, available_os_updates_request: str, session):
        response: Response = client.put('/mdm', data=available_os_updates_request, content_type='text/xml')
        assert response.status_code != 410
        assert response.status_code == 200

        d: Device = session.query(Device).filter(Device.udid == '00000000-1111-2222-3333-444455556666').one()
        updates = d.available_os_updates

        plist = plistlib.loads(available_os_updates_request.encode('utf8'))
        assert len(updates) == len(plist['AvailableOSUpdates'])
    def test_post_dep_profile_relationship(self, client: MDMClient, session):
        """Test assignment of DEP Profile to device via relationship URL:
            /api/v1/devices/<device_id>/relationships/dep_profiles"""
        request_json = json.dumps({
            "data": {
                "type": "dep_profiles",
                "id": "1",
            },
            "jsonapi": {
                "version": "1.0"
            }
        })

        response: Response = client.patch(
            "/api/v1/devices/1/relationships/dep_profile",
            data=request_json,
            content_type="application/vnd.api+json")
        print(response.data)
        assert response.status_code == 200

        d: Device = session.query(Device).filter(Device.id == 1).one()
        assert d.dep_profile_id is not None
Exemple #11
0
 def test_user_tokenupdate(self, client: MDMClient, tokenupdate_user_request: str):
     """Test a TokenUpdate message on the user channel."""
     response: Response = client.put('/checkin', data=tokenupdate_user_request, content_type='text/xml')
     assert response.status_code != 410
     assert response.status_code == 200