decode URL params into webhook event (#467)

Fixes #462
This commit is contained in:
Victor Vrantchan
2018-07-21 18:13:56 +00:00
committed by GitHub
parent d7f07bb022
commit 463fbbdeb2
4 changed files with 58 additions and 4 deletions

View File

@@ -1,3 +1,7 @@
## [v1.3.2]() TBD
* Fix URL params decoding.
## [v1.3.1](https://github.com/micromdm/micromdm/compare/v1.3.0...master) (Unreleased)
* Update base container to Alpine 3.7 (#437)

View File

@@ -6,7 +6,6 @@ import (
"time"
"github.com/go-kit/kit/endpoint"
"github.com/gorilla/mux"
"github.com/groob/plist"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
@@ -51,7 +50,11 @@ func (d *requestDecoder) decodeAcknowledgeRequest(ctx context.Context, r *http.R
return nil, errors.Wrap(err, "unmarshal MDM Response plist")
}
params := mux.Vars(r)
values := r.URL.Query()
params := make(map[string]string, len(values))
for k, v := range values {
params[k] = v[0]
}
event := AcknowledgeEvent{
ID: uuid.NewV4().String(),

View File

@@ -6,7 +6,6 @@ import (
"time"
"github.com/go-kit/kit/endpoint"
"github.com/gorilla/mux"
"github.com/groob/plist"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
@@ -84,7 +83,12 @@ func (d *requestDecoder) decodeCheckinRequest(ctx context.Context, r *http.Reque
return nil, errors.Wrap(err, "unmarshal MDM Checkin Request plist")
}
params := mux.Vars(r)
values := r.URL.Query()
params := make(map[string]string, len(values))
for k, v := range values {
params[k] = v[0]
}
event := CheckinEvent{
ID: uuid.NewV4().String(),
Time: time.Now().UTC(),

43
mdm/checkin_test.go Normal file
View File

@@ -0,0 +1,43 @@
package mdm
import (
"bytes"
"context"
"net/http/httptest"
"testing"
)
func Test_decodeCheckinRequest(t *testing.T) {
// test that url values from checkin and acknowledge requests are passed to the event.
req := httptest.NewRequest("GET", "/mdm/checkin?id=1111", bytes.NewReader([]byte(sampleCheckinRequest)))
dec := &requestDecoder{}
resp, err := dec.decodeCheckinRequest(context.Background(), req)
if err != nil {
t.Fatal(err)
}
response := resp.(checkinRequest)
if have, want := response.Event.Params["id"], "1111"; have != want {
t.Errorf("have %s, want %s", have, want)
}
}
const sampleCheckinRequest = `<?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>AwaitingConfiguration</key>
<false/>
<key>MessageType</key>
<string>TokenUpdate</string>
<key>PushMagic</key>
<string>AB62BB8A-7757-4130-94CC-CC8C5333D481</string>
<key>Token</key>
<data>
YWJjZGUK
</data>
<key>Topic</key>
<string>com.apple.mgmt.External.80bb2169-e864-4685-9a96-faa734f0b978</string>
<key>UDID</key>
<string>BC5E2DA4-7FB6-5E70-9928-4981680DAFBF</string>
</dict>
</plist>`