Skip to content

Commit

Permalink
cdh:golang: add unit tests for secure mount in ttrpc client
Browse files Browse the repository at this point in the history
add unit tests for secure mount in ttrpc client.

Signed-off-by: ChengyuZhu6 <[email protected]>
  • Loading branch information
ChengyuZhu6 authored and Xynnn007 committed Aug 28, 2024
1 parent 60648d2 commit 8b268ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
27 changes: 27 additions & 0 deletions confidential-data-hub/golang/pkg/ttrpc/api_ttrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,30 @@ func TestTtrpcUnsealFile(t *testing.T) {
assert.Nil(err)
assert.Equal("unsealed-value:unsealed content", resp)
}

func TestGrpcSecureMount(t *testing.T) {
assert := assert.New(t)

mockURL, err := mock.GenerateCDHTtrpcMockVSock()
assert.NoError(err)
defer mock.RemoveCDHTtrpcMockVSock(mockURL)

cdhMockServer := mock.CDHTtrpcMockServer{}
err = cdhMockServer.Start(mockURL)
assert.NoError(err)
defer cdhMockServer.Stop()

sockurl, err := url.Parse(mockURL)
assert.NoError(err)

c, err := CreateCDHTtrpcClient(sockurl.Path)
assert.NoError(err)
assert.NotNil(c)
defer c.Close()

ctx := context.Background()
options := map[string]string{"deviceId": "0:1", "encryptType": "LUKS", "dataIntegrity": "True"}
resp, err := common.SecureMount(ctx, c, "BlockDevice", options, []string{}, "/tmp/test-mount")
assert.Nil(err)
assert.Equal("/tmp/test-mount", resp)
}
7 changes: 7 additions & 0 deletions confidential-data-hub/golang/pkg/ttrpc/mock/mock_ttrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type CDHTtrpcMockServer struct {

func (cv *CDHTtrpcMockServer) ttrpcRegister(s *ttrpc.Server) {
cdhapi.RegisterSealedSecretServiceService(s, &cv.CDHTtrpcMockServerImp)
cdhapi.RegisterSecureMountServiceService(s, &cv.CDHTtrpcMockServerImp)
}

func (cv *CDHTtrpcMockServer) Start(socketAddr string) error {
Expand Down Expand Up @@ -96,3 +97,9 @@ func (p *CDHTtrpcMockServerImp) UnsealSecret(ctx context.Context, input *cdhapi.
output := cdhapi.UnsealSecretOutput{Plaintext: []byte("unsealed-value:" + strings.TrimPrefix(secret, SealedSecretPrefix))}
return &output, nil
}

func (p *CDHTtrpcMockServerImp) SecureMount(ctx context.Context, input *cdhapi.SecureMountRequest) (*cdhapi.SecureMountResponse, error) {
mountpoint := input.GetMountPoint()
output := cdhapi.SecureMountResponse{MountPath: mountpoint}
return &output, nil
}

0 comments on commit 8b268ba

Please sign in to comment.