Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix file backend pushinfo retrieval #135

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions storage/file/file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package file

import (
"context"
"testing"

"github.com/micromdm/nanomdm/storage/test"
)

func TestFileStorage(t *testing.T) {
s, err := New(t.TempDir())
if err != nil {
t.Fatal(err)
}

test.TestQueue(t, "EA4E19F1-7F8B-493D-BEAB-264B33BCF4E6", s)
test.TestRetrievePushInfo(t, context.Background(), s)
}
7 changes: 6 additions & 1 deletion storage/file/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package file
import (
"context"
"errors"
"os"

"github.com/micromdm/nanomdm/mdm"
)
Expand All @@ -13,7 +14,11 @@ func (s *FileStorage) RetrievePushInfo(_ context.Context, ids []string) (map[str
for _, id := range ids {
e := s.newEnrollment(id)
tokenUpdate, err := e.readFile(TokenUpdateFilename)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
// TokenUpdate file missing could be a non-existent or
// incomplete enrollment which should not trigger an error.
continue
} else if err != nil {
return nil, err
}
msg, err := mdm.DecodeCheckin(tokenUpdate)
Expand Down
17 changes: 0 additions & 17 deletions storage/file/queue_test.go

This file was deleted.

23 changes: 23 additions & 0 deletions storage/mysql/push_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package mysql

import (
"context"
"os"
"testing"

"github.com/micromdm/nanomdm/storage/test"
)

func TestRetrievePushInfo(t *testing.T) {
testDSN := os.Getenv("NANOMDM_MYSQL_STORAGE_TEST_DSN")
if testDSN == "" {
t.Skip("NANOMDM_MYSQL_STORAGE_TEST_DSN not set")
}

storage, err := New(WithDSN(testDSN), WithDeleteCommands())
if err != nil {
t.Fatal(err)
}

test.TestRetrievePushInfo(t, context.Background(), storage)
}
10 changes: 8 additions & 2 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ type ServiceStore interface {
BootstrapTokenStore
}

// PushStore stores and retrieves APNs push-related data.
// PushStore retrieves APNs push-related data.
type PushStore interface {
RetrievePushInfo(context.Context, []string) (map[string]*mdm.Push, error)
// RetrievePushInfo retrieves push data for the given ids.
//
// If an ID does not exist or is not enrolled properly then
// implementations should silently skip returning any push data for
// them. It is up to the caller to discern any missing IDs from the

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would one discern this is the case? Does this make it more obvious or less obvious what is going in from the consumer perspective?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller would need to compare the input set of IDs to the returned (output) set of IDs to see what's missing or different. This is how the MySQL backend works, fwiw.

// returned map.
RetrievePushInfo(ctx context.Context, ids []string) (map[string]*mdm.Push, error)
}

// PushCertStore stores and retrieves APNs push certificates.
Expand Down
19 changes: 19 additions & 0 deletions storage/test/push.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test

import (
"context"
"testing"

"github.com/micromdm/nanomdm/storage"
)

func TestRetrievePushInfo(t *testing.T, ctx context.Context, s storage.PushStore) {
t.Run("TestRetrievePushInfo", func(t *testing.T) {
_, err := s.RetrievePushInfo(ctx, []string{"INVALID"})
if err != nil {
// should NOT recieve a "global" error for an enrollment that
// is merely invalid (or not enrolled yet, or not fully enrolled)
t.Errorf("should NOT have errored: %v", err)
}
})
}