-
Notifications
You must be signed in to change notification settings - Fork 564
Adding structures for iot custom authorizer request/response #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d4946d7
Adding structures for iot custom authorizer request/response
ynori7 0354cec
Making the iot policy documents an array of strings to match the docu…
ynori7 08abc4f
Rebasing and updating iot events since the contract has chagned
ynori7 5e1a522
Making the api gateway custom authorizer policy more generic
ynori7 8d22e17
Fixed formatting
ynori7 49908ea
Merge remote-tracking branch 'upstream/master'
ynori7 52d992f
Merge branch 'master' of github.com:aws/aws-lambda-go
ynori7 b17b58c
Merge branch 'master' of github.com:aws/aws-lambda-go
ynori7 865df78
Merge branch 'main' into master
bmoffatt 52e690b
Merging
ynori7 bc772f2
Merging
ynori7 10076fa
Merge branch 'main' into master
bmoffatt 9d6212a
Merge branch 'main' into master
bmoffatt 435d2a5
Update iot.go
bmoffatt cb9ec66
Update iot.go
bmoffatt 97324c8
Delete workspace.xml
bmoffatt a914c1c
Delete vcs.xml
bmoffatt dc1ec3b
Delete misc.xml
bmoffatt d9bf306
Delete encodings.xml
bmoffatt c8643e0
Delete modules.xml
bmoffatt 05b402b
Delete aws-lambda-go.iml
bmoffatt 1975561
Delete policy.go
bmoffatt a6279db
Merge branch 'main' into master
bmoffatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package events | ||
|
||
// IoTCustomAuthorizerRequest contains data coming in to a custom IoT device gateway authorizer function. | ||
type IoTCustomAuthorizerRequest struct { | ||
HTTPContext *IoTHTTPContext `json:"httpContext,omitempty"` | ||
MQTTContext *IoTMQTTContext `json:"mqttContext,omitempty"` | ||
TLSContext *IoTTLSContext `json:"tlsContext,omitempty"` | ||
AuthorizationToken string `json:"token"` | ||
TokenSignature string `json:"tokenSignature"` | ||
} | ||
|
||
type IoTHTTPContext struct { | ||
Headers map[string]string `json:"headers,omitempty"` | ||
QueryString string `json:"queryString"` | ||
} | ||
|
||
type IoTMQTTContext struct { | ||
ClientID string `json:"clientId"` | ||
Password []byte `json:"password"` | ||
Username string `json:"username"` | ||
} | ||
|
||
type IoTTLSContext struct { | ||
ServerName string `json:"serverName"` | ||
} | ||
|
||
// IoTCustomAuthorizerResponse represents the expected format of an IoT device gateway authorization response. | ||
type IoTCustomAuthorizerResponse struct { | ||
IsAuthenticated bool `json:"isAuthenticated"` | ||
PrincipalID string `json:"principalId"` | ||
DisconnectAfterInSeconds int32 `json:"disconnectAfterInSeconds"` | ||
RefreshAfterInSeconds int32 `json:"refreshAfterInSeconds"` | ||
PolicyDocuments []string `json:"policyDocuments"` | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package events | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/aws/aws-lambda-go/events/test" | ||
) | ||
|
||
func TestIoTCustomAuthorizerRequestMarshaling(t *testing.T) { | ||
|
||
// read json from file | ||
inputJSON, err := ioutil.ReadFile("./testdata/iot-custom-auth-request.json") | ||
if err != nil { | ||
t.Errorf("could not open test file. details: %v", err) | ||
} | ||
|
||
// de-serialize into Go object | ||
var inputEvent IoTCustomAuthorizerRequest | ||
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { | ||
t.Errorf("could not unmarshal event. details: %v", err) | ||
} | ||
|
||
// serialize to json | ||
outputJSON, err := json.Marshal(inputEvent) | ||
if err != nil { | ||
t.Errorf("could not marshal event. details: %v", err) | ||
} | ||
|
||
test.AssertJsonsEqual(t, inputJSON, outputJSON) | ||
} | ||
|
||
func TestIoTCustomAuthorizerRequestMalformedJson(t *testing.T) { | ||
test.TestMalformedJson(t, IoTCustomAuthorizerRequest{}) | ||
} | ||
|
||
func TestIoTCustomAuthorizerResponseMarshaling(t *testing.T) { | ||
|
||
// read json from file | ||
inputJSON, err := ioutil.ReadFile("./testdata/iot-custom-auth-response.json") | ||
if err != nil { | ||
t.Errorf("could not open test file. details: %v", err) | ||
} | ||
|
||
// de-serialize into Go object | ||
var inputEvent IoTCustomAuthorizerResponse | ||
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { | ||
t.Errorf("could not unmarshal event. details: %v", err) | ||
} | ||
|
||
// serialize to json | ||
outputJSON, err := json.Marshal(inputEvent) | ||
if err != nil { | ||
t.Errorf("could not marshal event. details: %v", err) | ||
} | ||
|
||
test.AssertJsonsEqual(t, inputJSON, outputJSON) | ||
} | ||
|
||
func TestIoTCustomAuthorizerResponseMalformedJson(t *testing.T) { | ||
test.TestMalformedJson(t, IoTCustomAuthorizerResponse{}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"httpContext": { | ||
"headers": { | ||
"Accept-Language" : "en" | ||
}, | ||
"queryString": "abc" | ||
}, | ||
"mqttContext": { | ||
"clientId": "someclient", | ||
"password": "aslkfjwoeiuwekrujwlrueowieurowieurowiuerwleuroiwueroiwueroiuweoriuweoriuwoeiruwoeiur", | ||
"username": "thebestuser" | ||
}, | ||
"tlsContext": { | ||
"serverName": "server.stuff.com" | ||
}, | ||
"token": "someToken", | ||
"tokenSignature": "somelongtokensignature" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"isAuthenticated":true, | ||
"principalId": "xxxxxxxx", | ||
"disconnectAfterInSeconds": 86400, | ||
"refreshAfterInSeconds": 300, | ||
"policyDocuments": [ | ||
"{ \"Version\": \"2012-10-17\", \"Statement\": [ { \"Action\": [\"iot:Subscribe\"], \"Effect\": \"Allow\", \"Resource\": [\"*\"] } ] }" | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.