From fdf288da91f065e5a471d58dc83c1e02d0328d68 Mon Sep 17 00:00:00 2001 From: Scott Phillips Date: Fri, 11 Mar 2022 08:10:18 -0500 Subject: [PATCH 1/4] uuid ecosystem names --- go/go.mod | 1 + go/go.sum | 2 ++ go/services/services_test.go | 12 ++++-------- python/samples/vaccine_demo.py | 4 ++++ python/tests/test_trinsic_services.py | 11 ++++------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/go/go.mod b/go/go.mod index 8a0817a76..39a92bb42 100644 --- a/go/go.mod +++ b/go/go.mod @@ -3,6 +3,7 @@ module github.com/trinsic-id/sdk/go go 1.16 require ( + github.com/google/uuid v1.3.0 // indirect github.com/stretchr/testify v1.7.0 github.com/trinsic-id/okapi/go v1.4.0 google.golang.org/grpc v1.41.0 diff --git a/go/go.sum b/go/go.sum index 9d0fa9f41..2907c8259 100644 --- a/go/go.sum +++ b/go/go.sum @@ -54,6 +54,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= diff --git a/go/services/services_test.go b/go/services/services_test.go index 968d7d408..32d179beb 100644 --- a/go/services/services_test.go +++ b/go/services/services_test.go @@ -9,6 +9,7 @@ import ( "runtime" "testing" + "github.com/google/uuid" "github.com/stretchr/testify/assert" sdk "github.com/trinsic-id/sdk/go/proto" "google.golang.org/grpc" @@ -88,11 +89,6 @@ func TestServiceOptions(t *testing.T) { func TestVaccineCredentialsDemo(t *testing.T) { assert2 := assert.New(t) - err := createDefaultEcosystem() - if !assert2.Nil(err) { - return - } - // Open in background opts, err := NewServiceOptions(WithTestEnv()) if !assert2.Nil(err) { @@ -288,7 +284,7 @@ func createAccountAndSignIn(t *testing.T) (*assert.Assertions, *grpc.ClientConn, return assert2, accountService.GetChannel(), authtoken, nil } -func createDefaultEcosystem() error { +func createRandomEcosystem() error { opts, err := NewServiceOptions(WithTestEnv()) if err != nil { return err @@ -299,7 +295,7 @@ func createDefaultEcosystem() error { return err } - _, err = ps.CreateEcosystem(context.Background(), &sdk.CreateEcosystemRequest{Name: "default"}) + _, err = ps.CreateEcosystem(context.Background(), &sdk.CreateEcosystemRequest{Name: "test-sdk-" + uuid.New().String()}) return err } @@ -322,7 +318,7 @@ func TestEcosystemDemo(t *testing.T) { service.SetChannel(channel) actualCreate, err := service.CreateEcosystem(context.Background(), &sdk.CreateEcosystemRequest{ - Name: "Test-Ecosystem", + Name: "test-sdk-" + uuid.New().String(), Description: "My ecosystem", Uri: "https://example.com", }) diff --git a/python/samples/vaccine_demo.py b/python/samples/vaccine_demo.py index 235930acf..dcacdc9e8 100644 --- a/python/samples/vaccine_demo.py +++ b/python/samples/vaccine_demo.py @@ -119,6 +119,10 @@ async def vaccine_demo(): # print(f"Credential_status: {credential_status}") # assert credential_status.revoked is True # } + credentials_service.close() + wallet_service.close() + account_service.close() + provider_service.close() if __name__ == "__main__": diff --git a/python/tests/test_trinsic_services.py b/python/tests/test_trinsic_services.py index 940b94709..46a21dff9 100644 --- a/python/tests/test_trinsic_services.py +++ b/python/tests/test_trinsic_services.py @@ -1,21 +1,18 @@ import asyncio import platform import unittest -import uuid from samples.ecosystem_demo import ecosystem_demo from samples.provider_demo import provider_demo +from samples.templates_demo import templates_demo from samples.trustregistry_demo import trustregistry_demo from samples.vaccine_demo import vaccine_demo -from samples.templates_demo import templates_demo -from trinsic.proto.services.account.v1 import InfoResponse -from trinsic.proto.services.common.v1 import ResponseStatus -from trinsic.service_base import ResponseStatusException from trinsic.account_service import AccountService +from trinsic.proto.services.common.v1 import ResponseStatus from trinsic.provider_service import ProviderService -from trinsic.trustregistry_service import TrustRegistryService -from trinsic.wallet_service import WalletService +from trinsic.service_base import ResponseStatusException from trinsic.trinsic_util import trinsic_config +from trinsic.trustregistry_service import TrustRegistryService # Due to some issues with python and async io test cases, we have to run each sample in a separate asyncio event loop. From dfe0f8b39dc011f5f306e7c562f58bceb582aba5 Mon Sep 17 00:00:00 2001 From: Scott Phillips Date: Fri, 11 Mar 2022 08:26:01 -0500 Subject: [PATCH 2/4] go tests now pass - default to using TLS :) --- go/services/account_service.go | 3 +++ go/services/service_base.go | 18 ++++++++---------- go/services/service_base_test.go | 3 +-- go/services/services.go | 20 ++++++++------------ go/services/services_test.go | 25 +++++++++++-------------- 5 files changed, 31 insertions(+), 38 deletions(-) diff --git a/go/services/account_service.go b/go/services/account_service.go index f423fb513..9b875a03c 100644 --- a/go/services/account_service.go +++ b/go/services/account_service.go @@ -53,6 +53,9 @@ func (a *accountBase) SignIn(userContext context.Context, request *sdk.SignInReq if request == nil { request = &sdk.SignInRequest{} } + if request.Details == nil { + request.Details = &sdk.AccountDetails{} + } if len(request.EcosystemId) == 0 { request.EcosystemId = a.GetServiceOptions().DefaultEcosystem diff --git a/go/services/service_base.go b/go/services/service_base.go index 1d12c1662..bbdc6ee90 100644 --- a/go/services/service_base.go +++ b/go/services/service_base.go @@ -17,26 +17,23 @@ import ( // NewServiceBase returns a base service which is the foundation // for all the other services func NewServiceBase(options *Options) (Service, error) { - if options.Channel == nil { - conn, err := NewServiceConnection(options.ServiceOptions) - if err != nil { - return nil, err - } - - options.Channel = conn + conn, err := NewServiceConnection(options.ServiceOptions) + if err != nil { + return nil, err } return &serviceBase{ options: options, + channel: conn, securityProvider: &OberonSecurityProvider{}, }, nil } // Service defines functionality common to all services type Service interface { - // GetMetadatContext returns a context with the required grpc metadata embedded in it + // GetMetadataContext returns a context with the required grpc metadata embedded in it GetMetadataContext(userContext context.Context, message proto.Message) (context.Context, error) - // BuildMetdata builds the required grpc metadata + // BuildMetadata builds the required grpc metadata BuildMetadata(message proto.Message) (metadata.MD, error) // SetToken assigns the given auth token to the service. This token will be used for // make all api calls @@ -54,11 +51,12 @@ type Service interface { type serviceBase struct { options *Options + channel *grpc.ClientConn securityProvider SecurityProvider } func (s *serviceBase) GetChannel() *grpc.ClientConn { - return s.options.Channel + return s.channel } func (s *serviceBase) SetToken(authtoken string) { diff --git a/go/services/service_base_test.go b/go/services/service_base_test.go index 8c989fb86..4c8231c8b 100644 --- a/go/services/service_base_test.go +++ b/go/services/service_base_test.go @@ -49,7 +49,6 @@ func TestServiceBase(t *testing.T) { ServerPort: 1234, DefaultEcosystem: "test"}, ), - WithChannel(nconn), ) if !assert.Nil(err) { @@ -59,7 +58,7 @@ func TestServiceBase(t *testing.T) { base, err = NewServiceBase(opts) assert.Nil(err) assert.Equal(opts.ServiceOptions, base.GetServiceOptions()) - assert.Equal("192.168.1.1:4321", base.GetChannel().Target(), "new grpc connection should be set") + assert.Equal("127.0.0.1:1234", base.GetChannel().Target(), "new grpc connection should be set") // we should have an empty auth profile assert.Empty(base.GetProfile(), "auth Profile should be empty") diff --git a/go/services/services.go b/go/services/services.go index bbd301a39..e06b0bdda 100644 --- a/go/services/services.go +++ b/go/services/services.go @@ -6,13 +6,11 @@ import ( "strings" sdk "github.com/trinsic-id/sdk/go/proto" - "google.golang.org/grpc" ) //Options for configuring the sdk type Options struct { ServiceOptions *sdk.ServiceOptions - Channel *grpc.ClientConn } // NewServiceOptions returns a service options configuration with the provided options set @@ -119,20 +117,18 @@ func WithTestEnv() Option { s.ServiceOptions.ServerPort = int32(port) useTLS := os.Getenv("TEST_SERVER_USE_TLS") - if len(useTLS) != 0 && strings.Compare(strings.ToLower(useTLS), "false") != 0 { - s.ServiceOptions.ServerUseTls = true - } else { + if len(useTLS) != 0 && strings.Compare(strings.ToLower(useTLS), "false") == 0 { s.ServiceOptions.ServerUseTls = false + } else { + s.ServiceOptions.ServerUseTls = true } - return nil - } -} + defaultEcosystem := os.Getenv("TEST_SERVER_ECOSYSTEM") + if len(defaultEcosystem) > 0 { + } else { + s.ServiceOptions.DefaultEcosystem = "default" + } -// WithChannel will use the provided grpc channel instead of creating a default -func WithChannel(conn *grpc.ClientConn) Option { - return func(s *Options) error { - s.Channel = conn return nil } } diff --git a/go/services/services_test.go b/go/services/services_test.go index a9014f65d..f63cc72b4 100644 --- a/go/services/services_test.go +++ b/go/services/services_test.go @@ -12,7 +12,6 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/assert" sdk "github.com/trinsic-id/sdk/go/proto" - "google.golang.org/grpc" ) // pathData() { @@ -75,8 +74,6 @@ func TestVaccineCredentialsDemo(t *testing.T) { return } - opts.Channel = accountService.GetChannel() - // if !accountService.GetChannel().WaitForStateChange(context.Background(), connectivity.Ready) { // t.Fail() // } @@ -176,12 +173,12 @@ func TestVaccineCredentialsDemo(t *testing.T) { } func TestTrustRegistryDemo(t *testing.T) { - assert2, channel, authtoken, err := createAccountAndSignIn(t) + assert2, authtoken, err := createAccountAndSignIn(t) if !assert2.Nil(err) { return } - opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken), WithChannel(channel)) + opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken)) if !assert2.Nil(err) { return } @@ -238,23 +235,23 @@ func TestTrustRegistryDemo(t *testing.T) { assert2.NotEmpty(ecosystemList) } -func createAccountAndSignIn(t *testing.T) (*assert.Assertions, *grpc.ClientConn, string, error) { +func createAccountAndSignIn(t *testing.T) (*assert.Assertions, string, error) { assert2 := assert.New(t) opts, err := NewServiceOptions(WithTestEnv()) if !assert2.Nil(err) { - return assert2, nil, "", err + return assert2, "", err } // Open in background accountService, err := NewAccountService(opts) if !assert2.Nil(err) { - return assert2, nil, "", err + return assert2, "", err } authtoken, _, err := accountService.SignIn(context.Background(), &sdk.SignInRequest{}) if !assert2.Nil(err) { fmt.Println(err) - return assert2, nil, "", err + return assert2, "", err } - return assert2, accountService.GetChannel(), authtoken, nil + return assert2, authtoken, nil } func createRandomEcosystem() error { @@ -273,12 +270,12 @@ func createRandomEcosystem() error { return err } func TestEcosystemDemo(t *testing.T) { - assert2, channel, authtoken, err := createAccountAndSignIn(t) + assert2, authtoken, err := createAccountAndSignIn(t) if !assert2.Nil(err) { return } - opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken), WithChannel(channel)) + opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken)) if !assert2.Nil(err) { return } @@ -310,12 +307,12 @@ func TestEcosystemDemo(t *testing.T) { } func TestTemplatesDemo(t *testing.T) { - assert2, channel, authtoken, err := createAccountAndSignIn(t) + assert2, authtoken, err := createAccountAndSignIn(t) if !assert2.Nil(err) { return } - opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken), WithChannel(channel)) + opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken)) if !assert2.Nil(err) { return } From d54a7f5f5fa1324e766ec74edab1b16004d929a0 Mon Sep 17 00:00:00 2001 From: Scott Phillips Date: Fri, 11 Mar 2022 08:35:03 -0500 Subject: [PATCH 3/4] unblind a blinded account lol :facepalm: --- python/tests/test_trinsic_services.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/tests/test_trinsic_services.py b/python/tests/test_trinsic_services.py index 46a21dff9..9f29c3166 100644 --- a/python/tests/test_trinsic_services.py +++ b/python/tests/test_trinsic_services.py @@ -71,7 +71,6 @@ async def test_code(): asyncio.run(test_code()) - @unittest.skip("Account protection demo hangs") def test_protect_unprotect_account(self): async def test_code(): account_service = AccountService(server_config=trinsic_config()) @@ -83,7 +82,7 @@ async def test_code(): with self.assertRaises(Exception) as ve: await self.print_get_info(account_service, my_protected_profile) - my_unprotected_profile = account_service.unprotect(my_profile, code) + my_unprotected_profile = account_service.unprotect(my_protected_profile, code) # This hangs for unknown reasons. await self.print_get_info(account_service, my_unprotected_profile) From 0eb5e61c976ed23f0a196dbc989dfa063357968e Mon Sep 17 00:00:00 2001 From: Scott Phillips Date: Fri, 11 Mar 2022 15:20:09 -0500 Subject: [PATCH 4/4] no message --- .github/workflows/build-python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-python.yml b/.github/workflows/build-python.yml index 733f4f4fe..d94643bd7 100644 --- a/.github/workflows/build-python.yml +++ b/.github/workflows/build-python.yml @@ -56,8 +56,8 @@ jobs: API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }} LD_LIBRARY_PATH: "${{ github.workspace }}/libs" TEST_SERVER_ENDPOINT: ${{ secrets.TEST_SERVER_ENDPOINT }} - TEST_SERVER_PORT: ${{ secrets.TEST_SERVER_PORT }} - TEST_SERVER_USE_TLS: ${{ secrets.TEST_SERVER_USE_TLS }} + # TEST_SERVER_PORT: ${{ secrets.TEST_SERVER_PORT }} + # TEST_SERVER_USE_TLS: ${{ secrets.TEST_SERVER_USE_TLS }} - name: Upload Unit Test Results - Python if: always() uses: actions/upload-artifact@v2