mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-09 02:55:59 +08:00
Added mock push certificates and example script for cert generation Check that push cert has required UID com.apple.mgmt prefix Closes #367
30 lines
801 B
Go
30 lines
801 B
Go
package crypto
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestTopicFromValidCert(t *testing.T) {
|
|
certificate, _ := ReadPEMCertificateFile("testdata/mock_push_cert.pem")
|
|
pushTopic, err := TopicFromCert(certificate)
|
|
if err != nil {
|
|
t.Fatalf("fail %s", err)
|
|
}
|
|
|
|
if have, want := pushTopic, "com.apple.mgmt.External.18a16429-886b-41f1-9c30-2bd04ae4fc37"; have != want {
|
|
t.Errorf("have %s, want %s", have, want)
|
|
}
|
|
}
|
|
|
|
func TestTopicFromInvalidCert(t *testing.T) {
|
|
certFileNames := []string{"mock_push_cert_wrong_uid_prefix.pem", "mock_push_cert_wrong_uid_prefix.pem"}
|
|
for _, certFileName := range certFileNames {
|
|
certificate, _ := ReadPEMCertificateFile("testdata/" + certFileName)
|
|
_, err := TopicFromCert(certificate)
|
|
|
|
if err == nil {
|
|
t.Errorf("expected error for invalid push certificate")
|
|
}
|
|
}
|
|
}
|