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

Deal with session handling. #1505

Merged
merged 1 commit into from
Jan 15, 2025
Merged

Conversation

tecimovic
Copy link
Collaborator

This should resolve issues related to session handling.

There are two modes of operation:

1.) WITHOUT a passed appId, in which case we simply use a default value, and map the uuid to that key.
2.) WITH a passed appId (which is called "stsApplicationId" on the query string). In this case, this appId is being used to key the uuid inside the session map.

The second case is used when zap is rendered inside a system with multiple iframes, which share the same "sessionStorage", so you have to kepe session separate. That's why you can't simly use session storage directly.

The map ensures two things:
1.) When an iframe refreshes, with the same appId, it will reattach to the same sessionId.
2.) When a whole new iframe is created, and a new appId is passed, the whole new uuid will get created.

@paulr34 paulr34 requested a review from ethanzhouyc January 14, 2025 20:39
@ethanzhouyc
Copy link
Collaborator

For learning purposes: Could you explain why a sessionUuid is needed in addition to sessionId? Where does it function, and what is its relationship with sessionId?

Copy link
Collaborator

@brdandu brdandu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the pre-commit hook not being triggered for you to generate the API documentation with all the comments you added?

Is it possible to add unit tests to cover these changes?

*/
function saveSessionMap(window, map) {
const mapArray = Array.from(map)
const json = JSON.stringify(mapArray)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why convert this to json?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the "sessionStorage" only knows how to save "string => string" object types.
It is not designed to save javascript "Map". So you have to serialize/deserialize it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stared at it for a while in confusion, until I realized this to make it work......


// Session handling constants
const SESSION_KEY = 'session_uuid'
const APP_ID_KEY = 'stsApplicationId'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is an appId?
If a user opens 2 Z3Light applications then do we have 2 appIds for it or the same app Id?
Similarly what exactly is an Iframe in terms of a sample application?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"appId" is really a unique identifier for each "iframe". When an IDE opens multiple copies of ZAP in multiple iframes, each one gets one of those "appId" unique keys.

"iframe" in that context, is basically a separate ".zap" file. If you open 3 .zap files, you will have 3 iframes.

@paulr34 paulr34 merged commit f9674eb into project-chip:master Jan 15, 2025
13 checks passed
@tecimovic
Copy link
Collaborator Author

For learning purposes: Could you explain why a sessionUuid is needed in addition to sessionId? Where does it function, and what is its relationship with sessionId?

@ethanzhouyc : after this change the "sessionUuid" and the "sessionId" are one and the same thing. Before the change, the session ID was the uuid + appId, but now we're no longer propagating the appId into the back-end, we're merely using it as a key to the map between appId and uuid, and only the uuid travels to the back-end as a "sessionId".

@tecimovic tecimovic deleted the session-handling branch January 16, 2025 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants