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

Migrate the ban-sync component from matrix-appservice-irc #459

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

Half-Shot
Copy link
Contributor

@Half-Shot Half-Shot commented Feb 28, 2023

https://github.com/matrix-org/matrix-appservice-irc/blob/develop/src/bridge/MatrixBanSync.ts never really needed to live in the IRC bridge and in practice might be useful for other bridges.

I've been cheeky here and added an additional feature to check for open registration in the code.

The tests still need porting.

@Half-Shot Half-Shot requested a review from a team as a code owner February 28, 2023 16:22
Copy link
Contributor

@justinbot justinbot left a comment

Choose a reason for hiding this comment

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

Some readability suggestions but overall looks good.


}

public async getHomeserverProperties(serverName: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use jsdoc and return type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

public async getHomeserverProperties(serverName: string) {
const hsData = this.homeserverPropertiesCache.get(serverName);
// Slightly fuzz the ttl.
const ttl = CACHE_HOMESERVER_PROPERTIES_FOR_MS + (Math.random()*60000);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is missing a Date.now()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 91 to 94
const { url } = await this.hostResolver.resolveMatrixServer(serverName);
const registrationResponse = await axios.post(new URL('/_matrix/client/v3/register', url).toString(), { }, { });

let openReg = RegistrationStatus.Unknown;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would help readability to put this all this logic in a separate method which only handles returning a RegistrationStatus. Also that way it could return instead of mutating openReg.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

return hsProps;
}

public async syncRules(intent: Intent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use a jsdoc and return type.

}
else {
// Check the flows
for (const flow of flows) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Finding this loop a bit hard to follow, I think it could be more straightforward with a .map of flow stages to RegistrationStatus and then taking the minimum?

Just a suggestion feel free to ignore :)

}

const { url } = await this.hostResolver.resolveMatrixServer(serverName);
const registrationResponse = await axios.post(new URL('/_matrix/client/v3/register', url).toString(), { }, { });

Choose a reason for hiding this comment

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

What about older homeservers? If old homeservers only expose /_matrix/client/r0/register, will the bridge allow them to stay despite having open reg?

Copy link
Contributor Author

@Half-Shot Half-Shot Apr 20, 2023

Choose a reason for hiding this comment

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

Fair point, we'll include those.

Comment on lines 113 to 116
else if (flows.length === 0) {
// No available flows, so closed.
openReg = RegistrationStatus.Closed;
}

Choose a reason for hiding this comment

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

In the case of GNOME, I tried

>>> r = requests.post("https://gnome.modular.im/_matrix/client/v3/register", json={})
>>> r.json()
{'session': 'lpztxwMUAyTzgzdLHWhvwGtm', 'flows': [{'stages': ['m.login.recaptcha', 'm.login.terms', 'm.login.email.identity']}], 'params': {'m.login.recaptcha': {'public_key': '6LcgI54UAAAAABGdGmruw6DdOocFpYVdjYBRe4zb'}, 'm.login.terms': {'policies': {'privacy_policy': {'version': '1.0', 'en': {'name': 'Privacy Policy', 'url': 'https://gnome.modular.im/_matrix/consent?v=1.0'}}}}}}
>>> r.json()["flows"]
[{'stages': ['m.login.recaptcha', 'm.login.terms', 'm.login.email.identity']}]

It looks like the HS has open registrations, but in practice it's restricted to [email protected] email addresses. Is there a way to detect that remotely?

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.

3 participants