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

feat: e2e api #102

Merged
merged 9 commits into from
Jul 6, 2022
Merged

feat: e2e api #102

merged 9 commits into from
Jul 6, 2022

Conversation

tomicvladan
Copy link
Collaborator

Extension to extension API (#76)

@nugaon nugaon changed the title Feature/e2e api feat: e2e api Feb 21, 2022
)
class ExtensionDappSecurityContext extends DappSecurityContext {
constructor(private extensionId: string) {
super(extensionId)
Copy link
Member

Choose a reason for hiding this comment

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

maybe this will cause problem for allowed the storage key length. can you check what is the limit for that? Maybe would be better, if we transform the ID here to some prefixed and trimmed ID


this.securityContexts[sessionId] = new DappSecurityContext(tabId, frameId, frameContentRoot, originContentRoot)
if (this.isSenderExtension(sender)) {
context = new ExtensionDappSecurityContext(String(sessionId))
Copy link
Member

Choose a reason for hiding this comment

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

here the sessionId is the extension ID?

Copy link
Member

Choose a reason for hiding this comment

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

I'm telling you because the ExtensionDappSecurityContext has extensionId parameter naming

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
context = new ExtensionDappSecurityContext(String(sessionId))
context = new ExtensionDappSecurityContext(sessionId)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, this sessionId/extensionId is not needed at all.

action: A
sessionId: string
parameters: P
eventId?: string
Copy link
Member

Choose a reason for hiding this comment

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

let's make it required.

@nugaon nugaon self-requested a review February 22, 2022 13:15
Copy link
Member

@nugaon nugaon left a comment

Choose a reason for hiding this comment

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

So overall I think then ExtensionDappSecurityContext does not need to extend DappSecurityContext because in this form as you modified it only handles storage that external extensions do not use. Can we split then DappSecurityContext into a new abstract class that defines isValid method?
The storage related methods of DappSessionManager could throw error if it wants to use storage actions with extension context or something similar like this.

@tomicvladan
Copy link
Collaborator Author

OK. Then to remove the ExtensionDappSecurityContext class completely and restore the DappSecurityContext class to its original form? Without use of extension storage, extension security context is completely stateless and doesn't need security context at all.

@nugaon
Copy link
Member

nugaon commented Feb 23, 2022

now the context only relates to handling storage space, but later it also could track requests and limiting the allowed usage towards the Bee node or pair different API authorization tokens to different contexts. the Extension(s) also need security context, but for now it only has isValid method.

@vojtechsimetka
Copy link
Contributor

Can we revive this? Maybe it can be merged once the linter issues are solved. WDYT @nugaon @tomicvladan ?

@tomicvladan
Copy link
Collaborator Author

Hey @vojtechsimetka , now the linter error is fixed and I think it can be merged.

@nugaon nugaon self-requested a review June 29, 2022 15:04
Copy link
Member

@nugaon nugaon left a comment

Choose a reason for hiding this comment

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

I had an additional comment about the e2e api, but I sort of understand the consideration because of single source of truth concern.

But my other comment regarding to the extension context is really important, please do something with that before merge.

Comment on lines +125 to +165
private handleBzzLinkProtocolToFakeUrl(request: RequestType): string | null {
const {
sessionId,
parameters: { url, newPage },
} = request as BzzLinkProtocolToFakeUrlRequest

return bzzProtocolToFakeUrl(url, sessionId, newPage)
}

private handleBzzLinkUrlToFakeUrl(request: RequestType): string | null {
const {
sessionId,
parameters: { bzzLinkUrl, newPage },
} = request as BzzLinkLinkUrlToFakeUrlRequest

return bzzProtocolToFakeUrl(bzzLinkUrl, sessionId, newPage)
}

private handleBzzUrlToFakeUrl(request: RequestType): string | null {
const {
sessionId,
parameters: { url, newPage },
} = request as BzzLinkUrlToFakeUrlRequest

return bzzProtocolToFakeUrl(url, sessionId, newPage)
}

private handleWeb2FakeBeeApiAddress(request: RequestType): string {
const { sessionId } = request

return appendSwarmSessionIdToUrl(fakeUrl.beeApiAddress, sessionId)
}

private handleWeb2FakeBzzAddress(request: RequestType): string {
const {
sessionId,
parameters: { reference },
} = request as Web2HelprFakeBzzAddressRequest

return appendSwarmSessionIdToUrl(`${fakeUrl.bzzProtocol}/${reference}`, sessionId)
}
Copy link
Member

Choose a reason for hiding this comment

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

This logic could be completely on the other extension's side and you could save the async calls.

@@ -56,19 +85,45 @@ class DappSecurityContext {
}
}

class ExtensionDappSecurityContext extends DappSecurityContext {
constructor() {
super('extension')
Copy link
Member

Choose a reason for hiding this comment

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

this will mix two different and independent extension's context.
it should be distinguished by their extension id or only the blossom extension should be able to call the swarm-extension

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The ExtensionDappSecurityContext is actually stateless. If in the future we want to store some state, then we can use extension ID to distinguish different extensions.

Copy link
Member

Choose a reason for hiding this comment

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

it will be resolved later: #132

@nugaon nugaon self-requested a review July 6, 2022 10:09
@tomicvladan tomicvladan merged commit f0091b2 into master Jul 6, 2022
@tomicvladan tomicvladan deleted the feature/e2e-api branch July 6, 2022 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants