Skip to content
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

including transaction uuid field to scytale causes device to timeout #153

Open
ilawjr opened this issue Aug 24, 2020 · 4 comments
Open

including transaction uuid field to scytale causes device to timeout #153

ilawjr opened this issue Aug 24, 2020 · 4 comments
Assignees
Labels
wrp validator issues related to wrp validator
Milestone

Comments

@ilawjr
Copy link

ilawjr commented Aug 24, 2020

Including X-Xmidt-Transaction-Uuid and omitting the X-Xmidt-Source header in a direct request to Scytale can cause our simulators to timeout and and talaria to return a 504.

curl -X POST
https://$scytaleurl:443/api/v2/device
-H 'authorization: $auth'
-H 'content-type: application/json'
-H 'x-webpa-device-name: $testmac/config'
-H 'x-xmidt-content-type: application/json'
-H 'x-xmidt-message-type: 3'
-H 'x-xmidt-transaction-uuid: postman-1234'
-d ' {"command":"GET","names":["Device.DeviceInfo.X_CISCO_COM_FirmwareName"]}'

From side discussion with Joel, link map is in talaria.

Note: if you included X-Xmidt-Source, but omit X-Xmidt-Transaction-Uuid then you get a 200 return code, but an empty body.
tldr;
have the uuid and missing source -> 504
missing uuid and have source -> 200 (no body)
have the uuid and have source -> 200 + body
missing uuid and missing source - > 200 (no body)

@schmidtw
Copy link
Member

Is the x-xmidt-transaction-uuid value unique per message sent?

@joe94
Copy link
Member

joe94 commented Aug 25, 2020

Talaria assumes this UUID is unique per message and device (ok to use the same UUID when sending a message to different devices).

@joe94 joe94 added this to the Unreleased milestone Aug 27, 2020
@joe94 joe94 removed their assignment Sep 14, 2020
@kristinapathak
Copy link
Contributor

Talked with @schmidtw and according to the wrp spec both source and uuid are required so we should return a 400 instead of accepting malformed wrps.

@kristinapathak
Copy link
Contributor

This relies on xmidt-org/wrp-go#25 being fixed.

denopink added a commit to denopink/wrp-go that referenced this issue May 25, 2022
## Overview

related to xmidt-org#25, xmidt-org#78, xmidt-org/scytale#88, xmidt-org/talaria#153 s.t. we want a validation mechanism that is configurable by the application & verifies the spec.

### tl;rd
This pr introduces the initial validation framework, where applications supply validators (satisfying the `Validator interface`) to `NewMsgTypeValidator` and then used to verify the spec.

<details>
<summary> Explanation</summary>

Apps supply validators satisfying:
```go
// Validator is a WRP validator that allows access to the Validate function.
type Validator interface {
	Validate(m Message) error
}
```

and listing which validators are used on known and unknown msg types (where unknown msg types are handled by `defaultValidator`):
```go
var alwaysValidMsg ValidatorFunc = func(msg Message) error { return nil }
msgv, err := NewMsgTypeValidator(
	// Validates known msg types
	m: map[MessageType]Validators{SimpleEventMessageType: {alwaysValidMsg}},
	// Validates unknown msg types
	defaultValidator: alwaysValidMsg)
err = msgv.Validate(Message{Type: SimpleEventMessageType}) // Known msg type
err == nil // True
err = msgv.Validate(Message{Type: CreateMessageType}) // Unknown msg type, uses defaultValidator
err == nil // True
```

if a default validator is not provided, all unknown msg type will **fail** by default
```go
var alwaysValidMsg ValidatorFunc = func(msg Message) error { return nil }
msgv, err := NewMsgTypeValidator( // Omitted defaultValidator
	m: map[MessageType]Validators{SimpleEventMessageType: {alwaysInvalidMsg()}})
err = msgv.Validate(Message{Type: CreateMessageType})
err != nil // True
```
</details>

<details>
<summary>Type of Change(s)</summary>

- Non-breaking Enhancement
- All new and existing tests passed.

</details>

<details>
<summary>Module Unit Testing: [PASSING]</summary>

</details>

<details>
<summary>PR Affecting Unit Testing: validator_test.go [PASSING]</summary>

```console
Running tool: /usr/local/bin/go test -timeout 30s -run ^(TestHelperValidators|TestMsgTypeValidator)$ github.com/xmidt-org/wrp-go/v3

=== RUN   TestHelperValidators
=== RUN   TestHelperValidators/alwaysInvalidMsg
--- PASS: TestHelperValidators (0.00s)
    --- PASS: TestHelperValidators/alwaysInvalidMsg (0.00s)
=== RUN   TestMsgTypeValidator
=== RUN   TestMsgTypeValidator/MsgTypeValidator_validate
=== RUN   TestMsgTypeValidator/MsgTypeValidator_validate/known_message_type
=== RUN   TestMsgTypeValidator/MsgTypeValidator_validate/unknown_message_type_with_provided_default_Validator
=== RUN   TestMsgTypeValidator/MsgTypeValidator_validate/known_message_type_with_a_failing_Validator
=== RUN   TestMsgTypeValidator/MsgTypeValidator_validate/unknown_message_type_without_provided_default_Validator
=== RUN   TestMsgTypeValidator/MsgTypeValidator_factory
=== RUN   TestMsgTypeValidator/MsgTypeValidator_factory/with_provided_default_Validator
=== RUN   TestMsgTypeValidator/MsgTypeValidator_factory/without_provided_default_Validator
=== RUN   TestMsgTypeValidator/MsgTypeValidator_factory/empty_list_of_message_type_Validators
=== RUN   TestMsgTypeValidator/MsgTypeValidator_factory/empty_value_'m'_map[MessageType]Validators
--- PASS: TestMsgTypeValidator (0.00s)
    --- PASS: TestMsgTypeValidator/MsgTypeValidator_validate (0.00s)
        --- PASS: TestMsgTypeValidator/MsgTypeValidator_validate/known_message_type (0.00s)
        --- PASS: TestMsgTypeValidator/MsgTypeValidator_validate/unknown_message_type_with_provided_default_Validator (0.00s)
        --- PASS: TestMsgTypeValidator/MsgTypeValidator_validate/known_message_type_with_a_failing_Validator (0.00s)
        --- PASS: TestMsgTypeValidator/MsgTypeValidator_validate/unknown_message_type_without_provided_default_Validator (0.00s)
    --- PASS: TestMsgTypeValidator/MsgTypeValidator_factory (0.00s)
        --- PASS: TestMsgTypeValidator/MsgTypeValidator_factory/with_provided_default_Validator (0.00s)
        --- PASS: TestMsgTypeValidator/MsgTypeValidator_factory/without_provided_default_Validator (0.00s)
        --- PASS: TestMsgTypeValidator/MsgTypeValidator_factory/empty_list_of_message_type_Validators (0.00s)
        --- PASS: TestMsgTypeValidator/MsgTypeValidator_factory/empty_value_'m'_map[MessageType]Validators (0.00s)
PASS
ok      github.com/xmidt-org/wrp-go/v3  0.303s

> Test run finished at 5/25/2022, 11:39:22 AM <
```

</details>
@denopink denopink added the wrp validator issues related to wrp validator label Aug 8, 2022
@denopink denopink self-assigned this Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wrp validator issues related to wrp validator
Projects
None yet
Development

No branches or pull requests

5 participants