UserIDIsWithinApplicationServiceNamespace checks to see if a given userID falls within any of the namespaces of a given Application Service. If no Application Service is given, it will check to see if it matches any Application Service's namespace.
( cfg *config.ClientAPI, userID string, appservice *config.ApplicationService, )
| 401 | // Application Service is given, it will check to see if it matches any |
| 402 | // Application Service's namespace. |
| 403 | func UserIDIsWithinApplicationServiceNamespace( |
| 404 | cfg *config.ClientAPI, |
| 405 | userID string, |
| 406 | appservice *config.ApplicationService, |
| 407 | ) bool { |
| 408 | |
| 409 | var local, domain, err = gomatrixserverlib.SplitID('@', userID) |
| 410 | if err != nil { |
| 411 | // Not a valid userID |
| 412 | return false |
| 413 | } |
| 414 | |
| 415 | if domain != cfg.Matrix.ServerName { |
| 416 | return false |
| 417 | } |
| 418 | |
| 419 | if appservice != nil { |
| 420 | if appservice.SenderLocalpart == local { |
| 421 | return true |
| 422 | } |
| 423 | |
| 424 | // Loop through given application service's namespaces and see if any match |
| 425 | for _, namespace := range appservice.NamespaceMap["users"] { |
| 426 | // AS namespaces are checked for validity in config |
| 427 | if namespace.RegexpObject.MatchString(userID) { |
| 428 | return true |
| 429 | } |
| 430 | } |
| 431 | return false |
| 432 | } |
| 433 | |
| 434 | // Loop through all known application service's namespaces and see if any match |
| 435 | for _, knownAppService := range cfg.Derived.ApplicationServices { |
| 436 | if knownAppService.SenderLocalpart == local { |
| 437 | return true |
| 438 | } |
| 439 | for _, namespace := range knownAppService.NamespaceMap["users"] { |
| 440 | // AS namespaces are checked for validity in config |
| 441 | if namespace.RegexpObject.MatchString(userID) { |
| 442 | return true |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | return false |
| 447 | } |
| 448 | |
| 449 | // UsernameMatchesMultipleExclusiveNamespaces will check if a given username matches |
| 450 | // more than one exclusive namespace. More than one is not allowed |
no outgoing calls
no test coverage detected