Skip to content

Commit

Permalink
fix file backend pushinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed Jul 5, 2024
1 parent 3edec93 commit 02b4937
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
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)

Check failure on line 17 in storage/file/file_test.go

View workflow job for this annotation

GitHub Actions / format-build-test (1.19.x, ubuntu-latest)

undefined: test.TestRetrievePushInfo

Check failure on line 17 in storage/file/file_test.go

View workflow job for this annotation

GitHub Actions / format-build-test (1.19.x, macos-latest)

undefined: test.TestRetrievePushInfo

Check failure on line 17 in storage/file/file_test.go

View workflow job for this annotation

GitHub Actions / format-build-test (1.21.x, ubuntu-latest)

undefined: test.TestRetrievePushInfo

Check failure on line 17 in storage/file/file_test.go

View workflow job for this annotation

GitHub Actions / format-build-test (1.21.x, macos-latest)

undefined: test.TestRetrievePushInfo
}
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.

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
// returned map.
RetrievePushInfo(ctx context.Context, ids []string) (map[string]*mdm.Push, error)
}

// PushCertStore stores and retrieves APNs push certificates.
Expand Down

0 comments on commit 02b4937

Please sign in to comment.