cli/pkg/workspace/service_test.go
Snider 2b32633b7c Implement Authentication and Authorization Features (#314)
* Implement authentication and authorization features

- Define Workspace and Crypt interfaces in pkg/framework/core/interfaces.go
- Add Workspace() and Crypt() methods to Core in pkg/framework/core/core.go
- Implement PGP service in pkg/crypt/openpgp/service.go using ProtonMail go-crypto
- Implement Workspace service in pkg/workspace/service.go with encrypted directory structure
- Register new services in pkg/cli/app.go
- Add IPC handlers to both services for frontend/CLI communication
- Add unit tests for PGP service in pkg/crypt/openpgp/service_test.go

This implementation aligns the codebase with the features described in the README, providing a foundation for secure, encrypted workspaces and PGP key management.

* Implement authentication and authorization features with fixes

- Define Workspace and Crypt interfaces in pkg/framework/core/interfaces.go
- Add Workspace() and Crypt() methods to Core in pkg/framework/core/core.go
- Implement PGP service in pkg/crypt/openpgp/service.go using ProtonMail go-crypto
- Implement Workspace service in pkg/workspace/service.go with encrypted directory structure
- Register new services in pkg/cli/app.go with proper service names ('crypt', 'workspace')
- Add IPC handlers to both services for frontend/CLI communication
- Add unit tests for PGP and Workspace services
- Fix panic in PGP key serialization by using manual packet serialization
- Fix PGP decryption by adding armor decoding support

This implementation provides the secure, encrypted workspace manager features described in the README.

* Implement authentication and authorization features (Final)

- Define Workspace and Crypt interfaces in pkg/framework/core/interfaces.go
- Add Workspace() and Crypt() methods to Core in pkg/framework/core/core.go
- Implement PGP service in pkg/crypt/openpgp/service.go using ProtonMail go-crypto
- Implement Workspace service in pkg/workspace/service.go with encrypted directory structure
- Register new services in pkg/cli/app.go with proper service names ('crypt', 'workspace')
- Add IPC handlers to both services for frontend/CLI communication
- Add unit tests for PGP and Workspace services
- Fix panic in PGP key serialization by using manual packet serialization
- Fix PGP decryption by adding armor decoding support
- Fix formatting and unused imports

This implementation provides the secure, encrypted workspace manager features described in the README.

* Fix CI failure and implement auth features

- Fix auto-merge workflow by implementing it locally with proper repository context
- Implement Workspace and Crypt interfaces and services
- Add unit tests and IPC handlers for new services
- Fix formatting and unused imports in modified files
- Fix PGP key serialization and decryption issues

---------

Co-authored-by: Claude <developers@lethean.io>
2026-02-05 06:55:50 +00:00

55 lines
1.3 KiB
Go

package workspace
import (
"os"
"path/filepath"
"testing"
"github.com/host-uk/core/pkg/crypt/openpgp"
core "github.com/host-uk/core/pkg/framework/core"
"github.com/stretchr/testify/assert"
)
func TestWorkspace(t *testing.T) {
// Setup core with crypt service
c, _ := core.New(
core.WithName("crypt", openpgp.New),
)
tempHome, _ := os.MkdirTemp("", "core-test-home")
defer os.RemoveAll(tempHome)
// Mock os.UserHomeDir by setting HOME env
oldHome := os.Getenv("HOME")
os.Setenv("HOME", tempHome)
defer os.Setenv("HOME", oldHome)
s_any, err := New(c)
assert.NoError(t, err)
s := s_any.(*Service)
// Test CreateWorkspace
id, err := s.CreateWorkspace("test-user", "pass123")
assert.NoError(t, err)
assert.NotEmpty(t, id)
wsPath := filepath.Join(tempHome, ".core", "workspaces", id)
assert.DirExists(t, wsPath)
assert.DirExists(t, filepath.Join(wsPath, "keys"))
assert.FileExists(t, filepath.Join(wsPath, "keys", "private.key"))
// Test SwitchWorkspace
err = s.SwitchWorkspace(id)
assert.NoError(t, err)
assert.Equal(t, id, s.activeWorkspace)
// Test File operations
filename := "secret.txt"
content := "top secret info"
err = s.WorkspaceFileSet(filename, content)
assert.NoError(t, err)
got, err := s.WorkspaceFileGet(filename)
assert.NoError(t, err)
assert.Equal(t, content, got)
}