Skip to content

Commit

Permalink
add full check-in test
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed Apr 24, 2024
1 parent c6bc530 commit dfd2084
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion service/nanomdm/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,60 @@ import (
"context"
"testing"

"github.com/groob/plist"
"github.com/micromdm/nanomdm/mdm"
"github.com/micromdm/nanomdm/service"
)

func newTokenMDMReq() *mdm.Request {
return &mdm.Request{Context: context.Background()}
}

const tokenTestCheckin = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MessageType</key>
<string>GetToken</string>
<key>UDID</key>
<string>test</string>
<key>TokenServiceType</key>
<string>com.apple.maid</string>
</dict>
</plist>
`

func TestTokenFull(t *testing.T) {
tokenTestData := []byte("hello")

// create muxer
m := NewTokenMux()

// associate a new static token handler with a type
m.Handle("com.apple.maid", NewStaticToken(tokenTestData))

// create a new NanoMDM service with our token muxer
s := New(nil, WithGetToken(m))

// process GetToken check-in message
respBytes, err := service.CheckinRequest(s, newTokenMDMReq(), []byte(tokenTestCheckin))
if err != nil {
t.Fatal(err)
}

// unmarshal response bytes
resp := new(mdm.GetTokenResponse)
err = plist.Unmarshal(respBytes, resp)
if err != nil {
t.Fatal(err)
}

// check that our token data matches
if want, have := string(tokenTestData), string(resp.TokenData); have != want {
t.Errorf("have %q; want %q", have, want)
}
}

func newGetToken(serviceType string, id string) *mdm.GetToken {
return &mdm.GetToken{
TokenServiceType: serviceType,
Expand All @@ -28,7 +75,7 @@ func TestToken(t *testing.T) {
// associate a new static token handler with a type
m.Handle("com.apple.maid", NewStaticToken(tokenTestData))

// create a new NanoMDM service
// create a new NanoMDM service with our token muxer
s := New(nil, WithGetToken(m))

// dispatch a GetToken check-in message
Expand Down

0 comments on commit dfd2084

Please sign in to comment.