-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mysql storage backend queue test based on shared queue test code.
Note that this requires the hidden build flag `integration` as well as specifying a DSN flag for the test. As well the target DSN needs to exist and have the NanoMDM SQL schema present. You'll also need to clear those commands before every test.
- Loading branch information
1 parent
ca03a50
commit cbda10f
Showing
1 changed file
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//go:build integration | ||
|
||
package mysql | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"flag" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/micromdm/nanomdm/mdm" | ||
"github.com/micromdm/nanomdm/storage/internal/test" | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
) | ||
|
||
var flDSN = flag.String("dsn", "", "DSN of test MySQL instance") | ||
|
||
func loadAuthMsg() (*mdm.Authenticate, error) { | ||
b, err := ioutil.ReadFile("../../mdm/testdata/Authenticate.2.plist") | ||
if err != nil { | ||
return nil, err | ||
} | ||
r, err := mdm.DecodeCheckin(b) | ||
if err != nil { | ||
return nil, err | ||
} | ||
a, ok := r.(*mdm.Authenticate) | ||
if !ok { | ||
return nil, errors.New("not an Authenticate message") | ||
} | ||
return a, nil | ||
} | ||
|
||
func loadTokenMsg() (*mdm.TokenUpdate, error) { | ||
b, err := ioutil.ReadFile("../../mdm/testdata/TokenUpdate.2.plist") | ||
if err != nil { | ||
return nil, err | ||
} | ||
r, err := mdm.DecodeCheckin(b) | ||
if err != nil { | ||
return nil, err | ||
} | ||
a, ok := r.(*mdm.TokenUpdate) | ||
if !ok { | ||
return nil, errors.New("not a TokenUpdate message") | ||
} | ||
return a, nil | ||
} | ||
|
||
const deviceUDID = "66ADE930-5FDF-5EC4-8429-15640684C489" | ||
|
||
func newMdmReq() *mdm.Request { | ||
return &mdm.Request{ | ||
Context: context.Background(), | ||
EnrollID: &mdm.EnrollID{ | ||
Type: mdm.Device, | ||
ID: deviceUDID, | ||
}, | ||
} | ||
} | ||
|
||
func enrollTestDevice(storage *MySQLStorage) error { | ||
authMsg, err := loadAuthMsg() | ||
if err != nil { | ||
return err | ||
} | ||
err = storage.StoreAuthenticate(newMdmReq(), authMsg) | ||
if err != nil { | ||
return err | ||
} | ||
tokenMsg, err := loadTokenMsg() | ||
if err != nil { | ||
return err | ||
} | ||
err = storage.StoreTokenUpdate(newMdmReq(), tokenMsg) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func TestQueue(t *testing.T) { | ||
if *flDSN == "" { | ||
t.Fatal("MySQL DSN flag not provided to test") | ||
} | ||
|
||
storage, err := New(WithDSN(*flDSN)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = enrollTestDevice(storage) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
test.TestQueue(t, deviceUDID, storage) | ||
} |