checker: fix matrix federation test

This commit is contained in:
nemunaire 2021-03-12 12:28:25 +01:00
parent cd6a63fc57
commit 5d0693180d
1 changed files with 11 additions and 8 deletions

View File

@ -170,6 +170,7 @@ func check_https(domain, ip string) (err error) {
type matrix_result struct {
WellKnownResult struct {
Server string `json:"m.server"`
Result string `json:"result"`
}
DNSResult struct {
@ -187,7 +188,7 @@ type matrix_result struct {
Name string `json:"name"`
Version string `json:"version"`
}
FederationOK bool
FederationOK bool `json:"FederationOK"`
}
func check_matrix(domain string) (version string, err error) {
@ -199,16 +200,16 @@ func check_matrix(domain string) (version string, err error) {
defer resp.Body.Close()
if resp.StatusCode >= 300 {
return "", fmt.Errorf("Sorry, the federation tester is broken. Check on https://federationtester.matrix.org/#%s", domain)
return "", fmt.Errorf("Sorry, the federation tester is broken. Check on https://federationtester.matrix.org/#%s", strings.TrimSuffix(domain, "."))
}
var federationTest matrix_result
if federationTest.FederationOK {
if err = json.NewDecoder(resp.Body).Decode(&federationTest); err != nil {
log.Printf("Error in check_matrix, when decoding json: %w", err.Error())
return "", fmt.Errorf("Sorry, the federation tester is broken. Check on https://federationtester.matrix.org/#%s", strings.TrimSuffix(domain, "."))
} else if federationTest.FederationOK {
version = federationTest.Version.Name + " " + federationTest.Version.Version
return version, nil
} else if err = json.NewDecoder(resp.Body).Decode(&federationTest); err != nil {
log.Printf("Error in chech_matrix, when decoding json: %w", err.Error())
return "", fmt.Errorf("Sorry, the federation tester is broken. Check on https://federationtester.matrix.org/#%s", domain)
} else if federationTest.DNSResult.SRVError != nil && federationTest.WellKnownResult.Result != "" {
return "", fmt.Errorf("%s OR %s", federationTest.DNSResult.SRVError.Message, federationTest.WellKnownResult.Result)
} else if len(federationTest.ConnectionErrors) > 0 {
@ -222,8 +223,10 @@ func check_matrix(domain string) (version string, err error) {
msg.WriteString(cerr.Message)
}
return "", fmt.Errorf("Connection errors: %s", msg.String())
} else if federationTest.WellKnownResult.Server != strings.TrimSuffix(domain, ".") {
return "", fmt.Errorf("Bad homeserver_name: got %s, expected %s.", federationTest.WellKnownResult.Server, strings.TrimSuffix(domain, "."))
} else {
return "", fmt.Errorf("An unimplemented error occurs. Please report to nemunaire. But know that federation seems to be broken. Check https://federationtester.matrix.org/#%s", domain)
return "", fmt.Errorf("An unimplemented error occurs. Please report to nemunaire. But know that federation seems to be broken. Check https://federationtester.matrix.org/#%s", strings.TrimSuffix(domain, "."))
}
}
@ -348,7 +351,7 @@ func studentsChecker() {
}
}
// Check Matrix (only if GLUE Ok and)
// Check Matrix (only if GLUE Ok and defer contraint)
if glueErr == nil && istd%10 == check_matrix_for {
if v, err := check_matrix(std.MyDelegatedDomain()); err == nil {
if verbose {