Skip to content

Commit

Permalink
Merge pull request #3 from manicminer/test-fixups
Browse files Browse the repository at this point in the history
Test fixups and documentation updates
  • Loading branch information
manicminer authored Jan 17, 2021
2 parents d08da81 + 741cfed commit f23f399
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Contributions welcomed! Please see contribution guidelines in the [README](README.md).
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
11 changes: 6 additions & 5 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions clients/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 8 additions & 5 deletions clients/internal/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,6 +31,8 @@ func NewConnection() *Connection {
Environment: environments.Global,
TenantID: tenantId,
ClientID: clientId,
ClientCertPath: clientCertificate,
ClientCertPassword: clientCertPassword,
ClientSecret: clientSecret,
EnableClientCertAuth: true,
EnableClientSecretAuth: true,
Expand Down

0 comments on commit f23f399

Please sign in to comment.