Skip to content
This repository was archived by the owner on Jan 29, 2026. It is now read-only.

Commit e259e18

Browse files
committed
shared key and secret are now optional
When not specified requests that need to be signed will naturally fail
1 parent 01c9e3f commit e259e18

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ require (
66
github.com/go-playground/validator/v10 v10.0.1
77
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135
88
github.com/google/uuid v1.1.1
9-
github.com/philips-software/go-hsdp-signer v1.1.0
10-
github.com/stretchr/testify v1.4.0
9+
github.com/philips-software/go-hsdp-signer v1.1.1-0.20200417110351-20ce3021c3ba
10+
github.com/stretchr/testify v1.5.1
1111
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
1212
)
1313

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
2020
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
2121
github.com/philips-software/go-hsdp-signer v1.1.0 h1:7fYij8q7uCr2AOzO9g3X45FNB9tddFPnvR5WNLo3pD4=
2222
github.com/philips-software/go-hsdp-signer v1.1.0/go.mod h1:mtq3D20YNxHQ8e318ci9hVb3DW5Hlo30D3abN7VeqLM=
23+
github.com/philips-software/go-hsdp-signer v1.1.1-0.20200417110351-20ce3021c3ba h1:w3T8KnsMtPVAMgl4Qf/znYUGzsM2kysQPyA5JNptCqQ=
24+
github.com/philips-software/go-hsdp-signer v1.1.1-0.20200417110351-20ce3021c3ba/go.mod h1:/QehZ/+Aks2t1TFpjhF/7ZSB8PJIIJHzLc03rOqwLw0=
2325
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2426
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
2527
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2628
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
2729
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
30+
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
31+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
2832
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
2933
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
3034
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=

iam/client.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ func newClient(httpClient *http.Client, config *Config) (*Client, error) {
126126
return nil, err
127127
}
128128
signer, err := hsdpsigner.New(c.config.SharedKey, c.config.SecretKey)
129-
if err != nil {
130-
return nil, err
129+
if err != nil { // Allow nil signer
130+
signer = nil
131131
}
132132
if config.DebugLog != "" {
133133
c.debugFile, err = os.OpenFile(config.DebugLog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
@@ -517,6 +517,9 @@ func newResponse(r *http.Response) *Response {
517517

518518
// DoSigned performs a signed API request
519519
func (c *Client) DoSigned(req *http.Request, v interface{}) (*Response, error) {
520+
if c.signer == nil {
521+
return nil, ErrNoValidSignerAvailable
522+
}
520523
if err := c.signer.SignRequest(req); err != nil {
521524
return nil, err
522525
}

iam/client_test.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,20 @@ func setup(t *testing.T) func() {
3434
serverIDM = httptest.NewServer(muxIDM)
3535
sharedKey := "SharedKey"
3636
secretKey := "SecretKey"
37+
var err error
3738

38-
signerHSDP, _ = signer.New(sharedKey, secretKey)
39+
signerHSDP, err = signer.New(sharedKey, secretKey)
40+
assert.Nil(t, err)
3941

40-
client, _ = NewClient(nil, &Config{
42+
client, err = NewClient(nil, &Config{
4143
OAuth2ClientID: "TestClient",
4244
OAuth2Secret: "Secret",
4345
SharedKey: sharedKey,
4446
SecretKey: secretKey,
4547
IAMURL: serverIAM.URL,
4648
IDMURL: serverIDM.URL,
4749
})
50+
assert.Nil(t, err)
4851

4952
token = "44d20214-7879-4e35-923d-f9d4e01c9746"
5053
token2 := "55d20214-7879-4e35-923d-f9d4e01c9746"
@@ -78,6 +81,27 @@ func setup(t *testing.T) func() {
7881
}
7982
}
8083

84+
func TestWithMissingSigner(t *testing.T) {
85+
muxIAM = http.NewServeMux()
86+
serverIAM = httptest.NewServer(muxIAM)
87+
muxIDM = http.NewServeMux()
88+
serverIDM = httptest.NewServer(muxIDM)
89+
var err error
90+
91+
client, err = NewClient(nil, &Config{
92+
OAuth2ClientID: "TestClient",
93+
OAuth2Secret: "Secret",
94+
IAMURL: serverIAM.URL,
95+
IDMURL: serverIDM.URL,
96+
})
97+
assert.Nil(t, err)
98+
assert.NotNil(t, client)
99+
assert.Nil(t, client.signer)
100+
resp, err := client.DoSigned(&http.Request{}, nil)
101+
assert.Nil(t, resp)
102+
assert.Equal(t, ErrNoValidSignerAvailable, err)
103+
}
104+
81105
func TestLogin(t *testing.T) {
82106
teardown := setup(t)
83107
defer teardown()

iam/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var (
2323
ErrMissingEtagInformation = errors.New("missing etag information")
2424
ErrMissingRefreshToken = errors.New("missing refresh token")
2525
ErrNotAuthorized = errors.New("not authorized")
26+
ErrNoValidSignerAvailable = errors.New("no valid HSDP signer available")
2627
)
2728

2829
type UserError struct {

0 commit comments

Comments
 (0)