Commit Graph

29 Commits

Author SHA1 Message Date
mosen
8c42e2d7e1 Response testing 1 (#42)
* Create skeleton test suite for connect transport

* Remove service test because sqlmock never made it into the master branch.
Add transport test for connect loosely based on groobs management transport tests.

* Added mock command service.
Add single test for InstalledApplicationList
Add some modified real world responses as test data.

* Create fake device fixture for connect tests

* Add some more macOS responses.
Fix nullstring error in transport test.
proper teardown of httptest server.

* Even more responses from live system to use as test fixtures.

* Cleanup commented code.
Simple test for inserted applications with InstalledApplicationList response.

* Cleanup unused imports.

* Add tests for DeviceInformation and CertificateList.
Try to construct the command request in setup(), dirty hack.

* Use rollback instead of inline statements to destroy fixtures.
Fix incorrect plist in deviceinformation test.
Minor cleanups

* Add checkin authenticate test.
Fix some "down" migrations which didnt actually work.

* Basic coverage of checkin tests.
Fix invalid fixture base64 data.

* Tidy up mock management service and imports.

* Revert back to setup()/teardown() style per discussion with groob.

* Clean up imports
2016-11-06 21:15:46 +11:00
mosen
e4ab7e0b17 Hotfix/last check in (#34)
* Convert all time.Time pointers to value types.
Use UTC time when updating `last_checkin`.
Update `last_checkin` correctly on Authenticate, TokenUpdate, and query response.
Set database defaults to golangs zero value for time.Time which is `0001-01-01`.

* Add down migration for time defaults.
2016-10-12 16:20:48 +11:00
Victor Vrantchan
25dd485b13 update dependencies to latest version (#26) 2016-10-07 10:41:39 -04:00
mosen
bfdbc77a3a Non plural packages (#25)
* Stub new method for application datastore
Handle command failures more gracefully than continuously retrying. Failures are not logged
Add table for certificates.

(cherry picked from commit 9f580a6)

* Remove methods with signature NewDatastore() from datastores and injection of the logger instance into each datastore because groob is a doodoo head :)
Move NewDatastore methods into unit tests
Reinstate NewDB test
Create certificates package including a Certificate type and a datastore.
Began working on a method ackCertificateList in the connect service.
Boilerplate for management service test.
Renamed some tables in certificates migration, hopefully nobody notices.
Applications response handler should be omitted from this branch.

(cherry picked from commit 8bc2fc7)

* Add device uuid to certificate, as there will never be a normalised form of the certificate data.
Change statments to reflect table change from certificates to devices_certificates
Add the CertificateList request type to the connect service's Acknowledge method
Add certificates datastore to the management service, and add endpoints and request/responses for retrieving certificates by device uuid to the management endpoujnt.
Kludge. commits regarding app service will be amended.
(cherry picked from commit c723c80)

* Don't forget the endpoint definition for certificates!

(cherry picked from commit 4e5fc1f)

* Use byte field for certificate data.

(cherry picked from commit 66d5036)

* Fix empty import in certificates

(cherry picked from commit b6d4dca)

* Add table for certificates.

(cherry picked from commit 06bc231)

* Renamed some tables in certificates migration, hopefully nobody notices.
Rebase develop onto master

(cherry picked from commit 775484d)

* Certificate list responses are saved via replacing the entire certificate list on a per device basis. This is because neither the common name nor the data could be used as a unique constraint in the certificates table.
Few small changes to imports/style.

(cherry picked from commit e0a63e1)

* Properly rollback if certificate insert fails for any certificate in a response.

(cherry picked from commit 99e1ea1)

* Fix several incorrect statements and struct tags which were preventing the certificates management endpoint from listing certs.
Certificate listing is working without a base64 encoded representation of each certificate.

(cherry picked from commit 685dfef)

* Add commands index to command datastore.
Add simple test for commands index
Add commands index endpoint

(cherry picked from commit 4e2a2a2)

* Add handler for GET /mdm/commands

(cherry picked from commit ae71b8f)

* Added Find() method to commands datastore so that the request that matches a response can be retrieved by the connect service.
Added Find() method to command service

(cherry picked from commit ebceb28)

* Fix globally scoped vars in command datastore test suite

* groob prefers inline definition of struct members.

* Uppercase CommandUuid

* Add ackCertificateList to connect service, accidentally omitted from installed_certificate_list PR #14
Make push endpoint conform to Errorer interface.
Wrap error return in management service.
Add missing certsDB in main.go, should have been part of installed_certificate_list PR #14

* Fix erraneous comma in mdmEnrollResponse

* Rename certificates to certficiate
Rename applications to application
2016-10-07 12:35:06 +11:00
mosen
487f6826b0 Items that were omitted from cherry picking of installed_certificates_list (#22)
* Stub new method for application datastore
Handle command failures more gracefully than continuously retrying. Failures are not logged
Add table for certificates.

(cherry picked from commit 9f580a6)

* Remove methods with signature NewDatastore() from datastores and injection of the logger instance into each datastore because groob is a doodoo head :)
Move NewDatastore methods into unit tests
Reinstate NewDB test
Create certificates package including a Certificate type and a datastore.
Began working on a method ackCertificateList in the connect service.
Boilerplate for management service test.
Renamed some tables in certificates migration, hopefully nobody notices.
Applications response handler should be omitted from this branch.

(cherry picked from commit 8bc2fc7)

* Add device uuid to certificate, as there will never be a normalised form of the certificate data.
Change statments to reflect table change from certificates to devices_certificates
Add the CertificateList request type to the connect service's Acknowledge method
Add certificates datastore to the management service, and add endpoints and request/responses for retrieving certificates by device uuid to the management endpoujnt.
Kludge. commits regarding app service will be amended.
(cherry picked from commit c723c80)

* Don't forget the endpoint definition for certificates!

(cherry picked from commit 4e5fc1f)

* Use byte field for certificate data.

(cherry picked from commit 66d5036)

* Fix empty import in certificates

(cherry picked from commit b6d4dca)

* Add table for certificates.

(cherry picked from commit 06bc231)

* Renamed some tables in certificates migration, hopefully nobody notices.
Rebase develop onto master

(cherry picked from commit 775484d)

* Certificate list responses are saved via replacing the entire certificate list on a per device basis. This is because neither the common name nor the data could be used as a unique constraint in the certificates table.
Few small changes to imports/style.

(cherry picked from commit e0a63e1)

* Properly rollback if certificate insert fails for any certificate in a response.

(cherry picked from commit 99e1ea1)

* Fix several incorrect statements and struct tags which were preventing the certificates management endpoint from listing certs.
Certificate listing is working without a base64 encoded representation of each certificate.

(cherry picked from commit 685dfef)

* Add commands index to command datastore.
Add simple test for commands index
Add commands index endpoint

(cherry picked from commit 4e2a2a2)

* Add handler for GET /mdm/commands

(cherry picked from commit ae71b8f)

* Added Find() method to commands datastore so that the request that matches a response can be retrieved by the connect service.
Added Find() method to command service

(cherry picked from commit ebceb28)

* Fix globally scoped vars in command datastore test suite

* groob prefers inline definition of struct members.

* Uppercase CommandUuid

* Add ackCertificateList to connect service, accidentally omitted from installed_certificate_list PR #14
Make push endpoint conform to Errorer interface.
Wrap error return in management service.
Add missing certsDB in main.go, should have been part of installed_certificate_list PR #14
2016-10-07 11:57:04 +11:00
mosen
b3e97c53b2 installed_certificates #14 plus conflict resolution (#21)
* Stub new method for application datastore
Handle command failures more gracefully than continuously retrying. Failures are not logged
Add table for certificates.

(cherry picked from commit 9f580a6)

* Remove methods with signature NewDatastore() from datastores and injection of the logger instance into each datastore because groob is a doodoo head :)
Move NewDatastore methods into unit tests
Reinstate NewDB test
Create certificates package including a Certificate type and a datastore.
Began working on a method ackCertificateList in the connect service.
Boilerplate for management service test.
Renamed some tables in certificates migration, hopefully nobody notices.
Applications response handler should be omitted from this branch.

(cherry picked from commit 8bc2fc7)

* Add device uuid to certificate, as there will never be a normalised form of the certificate data.
Change statments to reflect table change from certificates to devices_certificates
Add the CertificateList request type to the connect service's Acknowledge method
Add certificates datastore to the management service, and add endpoints and request/responses for retrieving certificates by device uuid to the management endpoujnt.
Kludge. commits regarding app service will be amended.
(cherry picked from commit c723c80)

* Don't forget the endpoint definition for certificates!

(cherry picked from commit 4e5fc1f)

* Use byte field for certificate data.

(cherry picked from commit 66d5036)

* Fix empty import in certificates

(cherry picked from commit b6d4dca)

* Add table for certificates.

(cherry picked from commit 06bc231)

* Renamed some tables in certificates migration, hopefully nobody notices.
Rebase develop onto master

(cherry picked from commit 775484d)

* Certificate list responses are saved via replacing the entire certificate list on a per device basis. This is because neither the common name nor the data could be used as a unique constraint in the certificates table.
Few small changes to imports/style.

(cherry picked from commit e0a63e1)

* Properly rollback if certificate insert fails for any certificate in a response.

(cherry picked from commit 99e1ea1)

* Fix several incorrect statements and struct tags which were preventing the certificates management endpoint from listing certs.
Certificate listing is working without a base64 encoded representation of each certificate.

(cherry picked from commit 685dfef)

* Add commands index to command datastore.
Add simple test for commands index
Add commands index endpoint

(cherry picked from commit 4e2a2a2)

* Add handler for GET /mdm/commands

(cherry picked from commit ae71b8f)

* Added Find() method to commands datastore so that the request that matches a response can be retrieved by the connect service.
Added Find() method to command service

(cherry picked from commit ebceb28)

* Fix globally scoped vars in command datastore test suite

* groob prefers inline definition of struct members.

* Uppercase CommandUuid
2016-10-07 11:34:50 +11:00
mosen
bd5d996d73 Commands management plus fixes (#20)
* Add commands index to command datastore.
Add simple test for commands index
Add commands index endpoint

(cherry picked from commit 4e2a2a2)

* Add handler for GET /mdm/commands

(cherry picked from commit ae71b8f)

* Added Find() method to commands datastore so that the request that matches a response can be retrieved by the connect service.
Added Find() method to command service

(cherry picked from commit ebceb28)

* Fix globally scoped vars in command datastore test suite

* groob prefers inline definition of struct members.

* Uppercase CommandUuid
2016-10-07 11:17:47 +11:00
mosen
397087a800 Installed application list (#18)
* Add table `applications` and `devices_applications` for tracking installed applications per device and total installed application count.

(cherry picked from commit fba935d)

* Define new datastore for retrieving installed applications by device uuid
Add InstalledApps method to management service
Add endpoint for installed applications at /management/v1/devices/uuid/applications

(cherry picked from commit 07b2deb)

* REMOVED: Flesh out implementation of acknowledging InstalledApplicationList response.
Additional tags on Application for database.
Applications datastore supports select with arbitrary where clauses
Changed the signatures of all the ack handlers in connect service.

(cherry picked from commit f16b776)

* Revert acknowledge handlers code.
Add stub for acknowledging installed applications list.

(cherry picked from commit 82f7e3a)

* Fix some error strings in application datastore which still referred to devices.
Add method SaveApplicationByDeviceUUID to add rows to `devices_applications` for the specified device uuid
Add method NewDatastore since NewDB was untestable using mocks.
Connect service now takes an applications datastore as one of its parameters.
ackInstalledApplicationList implemented but not tested for InstallApplicationList responses.

(cherry picked from commit 97a97d9)

* Further comments on applications datastore.
Attempt to make some where clause helper functions.
Expand test suites to cover many different type of installed applications.
All tests passing.

(cherry picked from commit be99fcd)

* Additional comments
Fix methods which returned a pointer to a slice which is pointless.
Moved statement building functions in applications package to statement.go.
Fixed acknowledge handler if device UDID does not match any enrolled device (happens a lot in test cases).
Preliminary re-implementation of ackInstalledApplicationList
Added tests for the connect service.

(cherry picked from commit 92f253c)

* Add basic test for ackInstalledApplicationList

(cherry picked from commit 66ec74c)

* Fix wrong positional parameters.
Add handler for InstalledApplicationList request type.
installed applications are inserted but their relationship to the current device is not yet recorded. work in progress.

(cherry picked from commit e90c78d)

* Fixed slices which used make() showing the wrong capacity.
Removed a bunch of debug print statements.
Further enhanced connect service test with sql mocking.

(cherry picked from commit 0913934)

* Add regression test for bundle with size that is too large for int field.
Change applications table migration to use bigint field for `bundle_size`

(cherry picked from commit 3038d17)

* Note about difference between iOS and macOS Responses in comments.
Handle iOS response to InstalledApplicationList
Empty test for duplicate applications regression
Update management service test to fit new signature for NewService()

(cherry picked from commit db7c431)

* Changed application response storage to devices_applications, similar to certificates. Every time the device reports a new list, the application list gets replaced.
Add PayloadScope to enroll endpoint because interactive enrollment always seems to try to use the User scope.

(cherry picked from commit 0b0a01d)

* Merge change that removes NewDatastore() from applications/datastore.

* Add setup and teardown to application datastore test.
Remove existing tests because they were using the old Datastore interface.

* Remove invalid imports whoops

* Removed commented code.
Imported name device clashed with variable name device, renamed.

* Fix applications datastore New method in connect service test suite.

* Pull all vars out of global scope in connect service test.
2016-10-07 10:55:12 +11:00
Mosen
198b3b4720 Create type JsonNullString to allow NullString marshalling to JSON value. 2016-06-29 19:44:37 +10:00
Mosen
ee6107b52f Use sql.NullString where possible to allow us to put unique constraints on both UDID and SerialNumber
Remove default of empty string '' from udid column.
2016-06-29 19:01:26 +10:00
Mosen
586ba922b3 Do not capitalize errors. 2016-06-26 22:51:54 +10:00
Mosen
9a364d5c86 Use device datastore .Devices() method instead of GetDeviceByUDID.
Query by both device.SerialNumber and device.UDID
join WHERE conditions using the OR logical operator. I can't determine whether this has an impact elsewhere.
2016-06-25 22:19:39 +10:00
Mosen
e0aa275058 Actually include some fields in ackQueryResponses when fetching a Device to fix device query response update. 2016-06-25 22:02:47 +10:00
Mosen
00c8c9247f Set LastQueryResponse to byte slice.
Marshal LastQueryResponse to JSON in connect.Service
2016-06-24 16:26:20 +10:00
Mosen
2d08b9388e This time with the correct underlying Response struct in the connect endpoint. 2016-06-23 22:00:37 +10:00
Mosen
80aedab989 Converting request to mdm.Response was a bad idea. panic.
Update statement to reflect new composite key of udid and serial_number.
2016-06-23 17:33:14 +10:00
Mosen
5f73d44d8e Cast request object to mdm.Response in connect endpoint.
use devices.Save in ackQueryResponses
Remove methods UpdateDeviceQueryResponseByUDID and UpdateDeviceCheckinByUDID
Add message to devices.Save switch block for updating Query Responses.
2016-06-23 14:08:34 +10:00
Mosen
a89efaa2c0 Ditch checkin middleware.
Add QueryResponses to Device struct.
Move checkin update to ackQueryResponses.
2016-06-23 13:55:39 +10:00
Mosen
985db5752e Fix declaration of err variable in connect.Service.Acknowledge 2016-06-23 13:46:24 +10:00
Mosen
7ec8f51f70 Fix wrong method signature in connect.Service, thanks groob. 2016-06-23 13:40:51 +10:00
Mosen
15b5ec5cef Add service middleware for Connect service to record last_checkin each time a device contacts the MDM
Add method UpdateDeviceCheckinByUDID to device.Datastore which updates the current checkin timestamp for a given device.
Middleware set up in main.go
2016-06-22 19:10:38 +10:00
Mosen
621f5faf02 connect service Acknowledge updates information in devices table for QueryResponses
devices datastore updates QueryResponses into json column `last_query_response`, and some other main attributes into the devices table.
add migration to support column `last_query_response`.
2016-06-22 18:46:16 +10:00
Mosen
92dbc339b3 Change function signature of connect service Acknowledge/NextCommand to thread the Context and mdmConnectRequest through. 2016-06-22 17:39:32 +10:00
Victor Vrantchan
6367ee2367 add dep endpoint 2016-05-17 23:42:22 -04:00
Victor Vrantchan
ce131abf52 add push endpoint 2016-05-17 17:37:52 -04:00
Victor Vrantchan
1141ef3f80 connect service 2016-05-17 14:11:59 -04:00
Victor Vrantchan
01c5a0ba7a add initial setup 2016-05-09 17:14:09 -04:00
Victor Vrantchan
3043457851 dep features 2016-04-24 15:51:15 -04:00
Victor Vrantchan
2f232c194a first commit 2016-03-17 20:17:59 -04:00