Skip to content

Commit

Permalink
move
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho committed Feb 11, 2025
1 parent 2afb93c commit e0bbaa4
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 85 deletions.
2 changes: 0 additions & 2 deletions third_party/tailscale/distsign/rootkeys/doc.go

This file was deleted.

6 changes: 0 additions & 6 deletions third_party/tailscale/distsign/rootkeys/fs.go

This file was deleted.

73 changes: 0 additions & 73 deletions third_party/tailscale/distsign/rootkeys/fs_test.go

This file was deleted.

10 changes: 6 additions & 4 deletions third_party/tailscale/distsign/roots.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ package distsign

import (
"crypto/ed25519"
"embed"
"errors"
"fmt"
"path"
"path/filepath"
"sync"

"github.com/leptonai/gpud/third_party/tailscale/distsign/rootkeys"
)

//go:embed keys
var rootsFS embed.FS

var roots = sync.OnceValue(func() []ed25519.PublicKey {
roots, err := parseRoots()
if err != nil {
Expand All @@ -23,7 +25,7 @@ var roots = sync.OnceValue(func() []ed25519.PublicKey {
})

func parseRoots() ([]ed25519.PublicKey, error) {
files, err := rootkeys.RootsFS.ReadDir("keys")
files, err := rootsFS.ReadDir("keys")
if err != nil {
return nil, err
}
Expand All @@ -35,7 +37,7 @@ func parseRoots() ([]ed25519.PublicKey, error) {
if filepath.Ext(f.Name()) != ".pem" {
continue
}
raw, err := rootkeys.RootsFS.ReadFile(path.Join("keys", f.Name()))
raw, err := rootsFS.ReadFile(path.Join("keys", f.Name()))
if err != nil {
return nil, err
}
Expand Down
68 changes: 68 additions & 0 deletions third_party/tailscale/distsign/roots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,71 @@ func TestParseRoots(t *testing.T) {
t.Error("parseRoots returned no root keys")
}
}

func TestRootsFS(t *testing.T) {
// Test that we can list the embedded files
entries, err := rootsFS.ReadDir("keys")
if err != nil {
t.Fatalf("failed to read keys directory: %v", err)
}

// Verify we have exactly 2 files
if len(entries) != 2 {
t.Errorf("expected 2 files, got %d", len(entries))
}

// Expected files
expectedFiles := map[string]bool{
"gpud-root-1.pem": false,
"gpud-root-2.pem": false,
}

// Verify each file exists and can be read
for _, entry := range entries {
name := entry.Name()
if _, ok := expectedFiles[name]; !ok {
t.Errorf("unexpected file: %s", name)
continue
}
expectedFiles[name] = true

// Try to read the file
content, err := rootsFS.ReadFile("keys/" + name)
if err != nil {
t.Errorf("failed to read file %s: %v", name, err)
continue
}

// Verify the file is not empty
if len(content) == 0 {
t.Errorf("file %s is empty", name)
}
}

// Verify all expected files were found
for name, found := range expectedFiles {
if !found {
t.Errorf("expected file %s was not found", name)
}
}
}

func TestRootsFSErrors(t *testing.T) {
// Test reading non-existent directory
_, err := rootsFS.ReadDir("nonexistent")
if err == nil {
t.Error("expected error when reading non-existent directory")
}

// Test reading non-existent file
_, err = rootsFS.ReadFile("keys/nonexistent.pem")
if err == nil {
t.Error("expected error when reading non-existent file")
}

// Test reading a directory as a file
_, err = rootsFS.ReadFile("keys")
if err == nil {
t.Error("expected error when reading directory as file")
}
}

0 comments on commit e0bbaa4

Please sign in to comment.