Repository: matrix-org/synapse

Issue:
Misindention in saml2_config.sp_config section of generated configuration file
### Description

When one uses the `organization` and/or `contact_person` options for the SAML service provider, indented as in the generated `homeserver.yml`, synapse fails on startup with the following error.

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.7/site-packages/synapse/app/homeserver.py", line 651, in <module>
    main()
  File "/usr/local/lib/python3.7/site-packages/synapse/app/homeserver.py", line 646, in main
    hs = setup(sys.argv[1:])
  File "/usr/local/lib/python3.7/site-packages/synapse/app/homeserver.py", line 324, in setup
    "Synapse Homeserver", config_options
  File "/usr/local/lib/python3.7/site-packages/synapse/config/_base.py", line 629, in load_or_generate_config
    config_dict, config_dir_path=config_dir_path, data_dir_path=data_dir_path
  File "/usr/local/lib/python3.7/site-packages/synapse/config/_base.py", line 651, in parse_config_dict
    data_dir_path=data_dir_path,
  File "/usr/local/lib/python3.7/site-packages/synapse/config/_base.py", line 266, in invoke_all
    res[name] = getattr(config, func_name)(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/synapse/config/saml2_config.py", line 159, in read_config
    self.saml2_sp_config.load(saml2_config_dict)
  File "/usr/local/lib/python3.7/site-packages/saml2/config.py", line 382, in load
    self.load_complex(cnf, metadata_construction=metadata_construction)
  File "/usr/local/lib/python3.7/site-packages/saml2/config.py", line 316, in load_complex
    self.load_metadata(cnf["metadata"]))
  File "/usr/local/lib/python3.7/site-packages/saml2/config.py", line 425, in load_metadata
    mds.imp(metadata_conf)
  File "/usr/local/lib/python3.7/site-packages/saml2/mdstore.py", line 1023, in imp
    self.load(key, val)
  File "/usr/local/lib/python3.7/site-packages/saml2/mdstore.py", line 1008, in load
    raise SAMLError("Unknown metadata type '%s'" % typ)
saml2.SAMLError: Unknown metadata type 'organization'

```

The Problem is fixed by moving everything below the `metadata` option down by one indention level.
So this is an issue with the configuration file generating script, not with pysaml2.

### Steps to reproduce

- Generate `homeserver.yml` as described in the installation guide
- Uncomment in the `saml_config` section under `sp_config` the `metadata` option and at least one of `description`, `name`, `organization` and `contact_person`
- Start synapse

### Version information

- **Version**: Synapse v1.12.3
- **Install method**: Docker



Discussion:
Since I already fixed it locally, I can submit a PR later today, when I have time.
> Since I already fixed it locally, I can submit a PR later today, when I have time.

Thanks for the report, please submit a PR when you have time! 👍 

Resolving patch:
diff --git a/synapse/config/saml2_config.py b/synapse/config/saml2_config.py
--- a/synapse/config/saml2_config.py
+++ b/synapse/config/saml2_config.py
@@ -248,32 +248,32 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
           #    remote:
           #      - url: https://our_idp/metadata.xml
           #
-          #    # By default, the user has to go to our login page first. If you'd like
-          #    # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
-          #    # 'service.sp' section:
-          #    #
-          #    #service:
-          #    #  sp:
-          #    #    allow_unsolicited: true
+          #  # By default, the user has to go to our login page first. If you'd like
+          #  # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
+          #  # 'service.sp' section:
+          #  #
+          #  #service:
+          #  #  sp:
+          #  #    allow_unsolicited: true
           #
-          #    # The examples below are just used to generate our metadata xml, and you
-          #    # may well not need them, depending on your setup. Alternatively you
-          #    # may need a whole lot more detail - see the pysaml2 docs!
+          #  # The examples below are just used to generate our metadata xml, and you
+          #  # may well not need them, depending on your setup. Alternatively you
+          #  # may need a whole lot more detail - see the pysaml2 docs!
           #
-          #    description: ["My awesome SP", "en"]
-          #    name: ["Test SP", "en"]
+          #  description: ["My awesome SP", "en"]
+          #  name: ["Test SP", "en"]
           #
-          #    organization:
-          #      name: Example com
-          #      display_name:
-          #        - ["Example co", "en"]
-          #      url: "http://example.com"
+          #  organization:
+          #    name: Example com
+          #    display_name:
+          #      - ["Example co", "en"]
+          #    url: "http://example.com"
           #
-          #    contact_person:
-          #      - given_name: Bob
-          #        sur_name: "the Sysadmin"
-          #        email_address": ["admin@example.com"]
-          #        contact_type": technical
+          #  contact_person:
+          #    - given_name: Bob
+          #      sur_name: "the Sysadmin"
+          #      email_address": ["admin@example.com"]
+          #      contact_type": technical
 
           # Instead of putting the config inline as above, you can specify a
           # separate pysaml2 configuration file:


Test patch: