From 6ad14c7e0eb8b81a668bb71f168f77607a9409b9 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Sun, 17 Jan 2021 23:10:18 +0000 Subject: [PATCH 1/2] Fix client certificate auth for tests, ensure objects are cleaned up --- auth/auth_test.go | 11 ++++++----- clients/groups_test.go | 1 + clients/internal/testing.go | 13 ++++++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/auth/auth_test.go b/auth/auth_test.go index 14d0c203..5c577cf1 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -10,15 +10,16 @@ import ( ) var ( - tenantId = os.Getenv("TENANT_ID") - clientId = os.Getenv("CLIENT_ID") - clientCertificate = os.Getenv("CLIENT_CERTIFICATE") - clientSecret = os.Getenv("CLIENT_SECRET") + tenantId = os.Getenv("TENANT_ID") + clientId = os.Getenv("CLIENT_ID") + clientCertificate = os.Getenv("CLIENT_CERTIFICATE") + clientCertPassword = os.Getenv("CLIENT_CERTIFICATE_PASSWORD") + clientSecret = os.Getenv("CLIENT_SECRET") ) func TestClientCertificateAuthorizer(t *testing.T) { ctx := context.Background() - auth, err := auth.NewClientCertificateAuthorizer(ctx, environments.Global, tenantId, clientId, clientCertificate, "") + auth, err := auth.NewClientCertificateAuthorizer(ctx, environments.Global, tenantId, clientId, clientCertificate, clientCertPassword) if err != nil { t.Errorf("NewClientCertificateAuthorizer(): %v", err) } diff --git a/clients/groups_test.go b/clients/groups_test.go index f718c198..51e1a35b 100644 --- a/clients/groups_test.go +++ b/clients/groups_test.go @@ -79,6 +79,7 @@ func TestGroupsClient(t *testing.T) { testGroupsClient_List(t, c) testGroupsClient_Delete(t, c, *group.ID) + testUsersClient_Delete(t, u, *user.ID) } func testGroupsClient_Create(t *testing.T, c GroupsClientTest, g models.Group) (group *models.Group) { diff --git a/clients/internal/testing.go b/clients/internal/testing.go index 03caafea..9abadcfa 100644 --- a/clients/internal/testing.go +++ b/clients/internal/testing.go @@ -10,11 +10,12 @@ import ( ) var ( - tenantId = os.Getenv("TENANT_ID") - tenantDomain = os.Getenv("TENANT_DOMAIN") - clientId = os.Getenv("CLIENT_ID") - //clientCertificate = os.Getenv("CLIENT_CERTIFICATE") - clientSecret = os.Getenv("CLIENT_SECRET") + tenantId = os.Getenv("TENANT_ID") + tenantDomain = os.Getenv("TENANT_DOMAIN") + clientId = os.Getenv("CLIENT_ID") + clientCertificate = os.Getenv("CLIENT_CERTIFICATE") + clientCertPassword = os.Getenv("CLIENT_CERTIFICATE_PASSWORD") + clientSecret = os.Getenv("CLIENT_SECRET") ) type Connection struct { @@ -30,6 +31,8 @@ func NewConnection() *Connection { Environment: environments.Global, TenantID: tenantId, ClientID: clientId, + ClientCertPath: clientCertificate, + ClientCertPassword: clientCertPassword, ClientSecret: clientSecret, EnableClientCertAuth: true, EnableClientSecretAuth: true, From 741cfedc8b8ef1b8ca0e27f9316e8dcaf7a678eb Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Sun, 17 Jan 2021 23:10:35 +0000 Subject: [PATCH 2/2] Update documentation for contributing/testing --- CONTRIBUTING.md | 1 + README.md | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..e2192341 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1 @@ +Contributions welcomed! Please see contribution guidelines in the [README](README.md). \ No newline at end of file diff --git a/README.md b/README.md index 6373b0ed..6c454146 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Hamilton is a Go SDK for Microsoft Graph -This is a working Go client for the [Microsoft Graph API][ms-graph-docs]. It is actively maintained and has growing support for services and objects in Azure Active Directory. +This is a working Go client for the [Microsoft Graph API][ms-graph-docs]. It is actively maintained and has growing +support for services and objects in Azure Active Directory. ## Example Usage @@ -56,4 +57,25 @@ func main() { } ``` +## Contributing + +Contributions are welcomed! Please note that clients must have tests that cover all methods where feasible. + +Please raise a pull request on GitHub to submit contributions. Bug reports and feature requests are happily received. + +## Testing + +Testing requires an Azure AD tenant and real credentials. You can authenticate with any supported method for the client +tests, and the auth tests are split by authentication method. + +Note that each client generally has a single test that exercises all methods. This is to help ensure that test objects +are cleaned up where possible. Where tests fail, often objects will be left behind and should be cleaned up manually. + +It's recommended to use an isolated tenant for testing and _not_ a production tenant. + +To run all the tests: +```shell +$ make test +``` + [ms-graph-docs]: https://docs.microsoft.com/en-us/graph/overview