Skip to content

Consistent custom attributes for HELLO + separate tests set #542

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

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/wampy.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,10 +838,11 @@ class Wampy {
}

const messageOptions = {
...helloCustomDetails,
...this._extractCustomOptions(helloCustomDetails),
...this._wamp_features,
...(authid ? { authid, authmethods, authextra } : {}),
};
// WAMP SPEC: [HELLO, Realm|string, Details|dict]
const encodedMessage = this._encode([WAMP_MSG_SPEC.HELLO, realm, messageOptions]);

if (encodedMessage) {
Expand Down Expand Up @@ -1927,12 +1928,12 @@ class Wampy {
acknowledge: true,
...messageOptions,
...(ppt_scheme ? { ppt_scheme } : {}),
...(ppt_scheme ? { ppt_scheme } : {}),
...(ppt_serializer ? { ppt_serializer } : {}),
...(ppt_cipher ? { ppt_cipher } : {}),
...(ppt_keyid ? { ppt_keyid } : {}),
...(exclude_me ? { exclude_me } : {}),
...(disclose_me ? { disclose_me } : {}),
...(retain ? { retain } : {}),
...this._extractCustomOptions(advancedOptions)
};

Expand Down
188 changes: 188 additions & 0 deletions test/custom-attributes-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import { WAMP_MSG_SPEC } from "../src/constants.js";

const customAttrsData = [
// Test custom attributes in outgoing messages by checking what client sends
{
trigger: {
messageType: WAMP_MSG_SPEC.SUBSCRIBE,
condition: (msg) => {
const options = msg[2];
// Verify custom attributes are present in SUBSCRIBE options
return (
options._tracking_id === "sub_12345" &&
options._priority === "high" &&
options._custom_auth === "bearer_token"
);
},
},
response: [WAMP_MSG_SPEC.SUBSCRIBED, "REQUEST_ID", 1001],
},

{
trigger: {
messageType: WAMP_MSG_SPEC.PUBLISH,
condition: (msg) => {
const options = msg[2];
// Verify custom attributes are present in PUBLISH options
return (
options._tracking_id === "pub_67890" &&
options._priority === "urgent" &&
options._routing_hint === "datacenter_west"
);
},
},
response: [WAMP_MSG_SPEC.PUBLISHED, "REQUEST_ID", 2001],
},

{
trigger: {
messageType: WAMP_MSG_SPEC.CALL,
condition: (msg) => {
const options = msg[2];
// Verify custom attributes are present in CALL options
return (
options._request_id === "call_abcdef" &&
options._timeout_override === 30000 &&
options._auth_context === "admin_user"
);
},
},
response: [
WAMP_MSG_SPEC.RESULT,
"REQUEST_ID",
{},
[{ argsList: ["custom", "call", "result"] }],
],
},

{
trigger: {
messageType: WAMP_MSG_SPEC.CANCEL,
condition: (msg) => {
const options = msg[2];
// Verify custom attributes are present in CANCEL options
return (
options._cancel_reason === "user_requested" &&
options._priority === "immediate" &&
options.mode === "kill"
);
},
},
// CANCEL doesn't get a direct response, but we can verify it was received
response: null,
},

{
trigger: {
messageType: WAMP_MSG_SPEC.REGISTER,
condition: (msg) => {
const options = msg[2];
// Verify custom attributes are present in REGISTER options
return (
options._handler_version === "2.1.0" &&
options._load_balancing === "round_robin" &&
options._timeout_hint === 5000
);
},
},
response: [WAMP_MSG_SPEC.REGISTERED, "REQUEST_ID", 3001],
},

// Test mixed standard + custom options
{
trigger: {
messageType: WAMP_MSG_SPEC.CALL,
condition: (msg) => {
const options = msg[2];
// Verify both standard and custom attributes
return (
options.timeout === 5000 &&
options.disclose_me === true &&
options._tracking_id === "mixed_123" &&
options._priority === "high"
);
},
},
response: [
WAMP_MSG_SPEC.RESULT,
"REQUEST_ID",
{},
[{ argsList: ["mixed", "options", "result"] }],
],
},

{
trigger: {
messageType: WAMP_MSG_SPEC.PUBLISH,
condition: (msg) => {
const options = msg[2];
// Verify both standard and custom attributes
return (
options.exclude_me === false &&
options.disclose_me === true &&
options._event_type === "notification" &&
options._source_system === "billing"
);
},
},
response: [WAMP_MSG_SPEC.PUBLISHED, "REQUEST_ID", 4001],
},

{
trigger: {
messageType: WAMP_MSG_SPEC.SUBSCRIBE,
condition: (msg) => {
const options = msg[2];
// Verify both standard and custom attributes for prefix subscription
return (
options.match === "prefix" &&
options._subscription_type === "live" &&
options._filter_level === "debug"
);
},
},
response: [WAMP_MSG_SPEC.SUBSCRIBED, "REQUEST_ID", 5002],
},

{
trigger: {
messageType: WAMP_MSG_SPEC.REGISTER,
condition: (msg) => {
const options = msg[2];
// Verify both standard and custom attributes
return (
options.invoke === "roundrobin" &&
options._handler_type === "async" &&
options._max_concurrency === 10
);
},
},
response: [WAMP_MSG_SPEC.REGISTERED, "REQUEST_ID", 6002],
},

// Test invalid custom attributes (should be filtered out)
{
trigger: {
messageType: WAMP_MSG_SPEC.CALL,
condition: (msg) => {
const options = msg[2];
// Should only have valid custom attributes, invalid ones filtered
return (
options._valid_attr === "valid" &&
!options._x && // Too short - should be filtered
!options._X && // Uppercase - should be filtered
!options["_invalid-dash"] && // Contains dash - should be filtered
!options.no_underscore
); // No underscore - should be filtered
},
},
response: [
WAMP_MSG_SPEC.RESULT,
"REQUEST_ID",
{},
[{ argsList: ["filtered", "result"] }],
],
},
];

export default customAttrsData;
Loading