def test_if_instance_id_is_save_to_config_file(self, mock_identify_existing_config_file, logger):
     server_config = self._setup_server_config()
     new_gui_config = create_new_configuration_dict()
     instance_id = "my_instance_id"
     mock_identify_existing_config_file.return_value = None
     config_dict = convert_config_gui_structure(new_gui_config, 0, instance_id, True, server_config)
     assert all(item in config_dict.items() for item in {"instance_id": instance_id}.items())
Example #2
0
def handle_start_test_instance(session, response_encoder, parameters):
    if 'op_configurations' not in parameters:
        return response_encoder.bad_request()

    config_gui_structure = parameters['op_configurations']
    _profile = generate_profile(config_gui_structure)
    _instance_id = session[INSTANCE_ID_QUERY_KEY]
    _port = None

    if is_using_dynamic_client_registration(config_gui_structure):
        try:
            issuer = get_issuer_from_gui_config(config_gui_structure)
            _port = allocate_dynamic_port(issuer, _instance_id)
        except NoPortAvailable:
            pass
    else:
        if "port" in session:
            _port = session['port']

    if not _port:
        raise NoPortAvailable(
            NO_PORT_ERROR_MESSAGE,
            log_info="Failed to allocate a port used for dynamic client "
            "registration since no port where available",
            show_trace=False)

    config_string = convert_config_gui_structure(config_gui_structure, _port,
                                                 _instance_id,
                                                 is_port_in_database(_port),
                                                 CONF)

    session[OP_CONFIG] = validate_configuration_size(config_string)
    return restart_test_instance(_instance_id, _port, _profile,
                                 response_encoder, session[OP_CONFIG])
 def test_do_not_overwrite_custom_value_config_file(self, mock_identify_existing_config_file, logger):
     server_config = self._setup_server_config()
     custom_info = {"custom_key": "custom_value"}
     mock_identify_existing_config_file.return_value = copy.deepcopy(custom_info)
     new_gui_config = create_new_configuration_dict()
     config_dict = convert_config_gui_structure(new_gui_config, 0, "id", True, server_config)
     assert all(item in config_dict.items() for item in custom_info.items())
Example #4
0
def handle_start_test_instance(session, response_encoder, parameters):
    if 'op_configurations' not in parameters:
        return response_encoder.bad_request()

    config_gui_structure = parameters['op_configurations']
    _profile = generate_profile(config_gui_structure)
    _instance_id = session[INSTANCE_ID_QUERY_KEY]
    _port = None

    if is_using_dynamic_client_registration(config_gui_structure):
        try:
            issuer = get_issuer_from_gui_config(config_gui_structure)
            _port = allocate_dynamic_port(issuer, _instance_id)
        except NoPortAvailable:
            pass
    else:
        if "port" in session:
            _port = session['port']

    if not _port:
        raise NoPortAvailable(NO_PORT_ERROR_MESSAGE,
                              log_info="Failed to allocate a port used for dynamic client "
                                       "registration since no port where available",
                              show_trace=False)

    config_string = convert_config_gui_structure(config_gui_structure,
                                                 _port,
                                                 _instance_id,
                                                 is_port_in_database(_port),
                                                 CONF)

    session[OP_CONFIG] = validate_configuration_size(config_string)
    return restart_test_instance(_instance_id, _port, _profile, response_encoder,
                                 session[OP_CONFIG])
Example #5
0
    def test_overwrite_static_with_dynamic_discovery(
            self, mock_identify_existing_config_file):
        server_config = self._setup_server_config()
        static_client_discovery_info = {
            "provider_info": {
                "jwks_uri": "example.com/jwks",
                "authorization_endpoint": "example.com/auth",
                "response_types_supported": "response_types_supported",
                "id_token_signing_alg_values_supported": ['alg'],
                "subject_types_supported": ['subject_type'],
                "issuer": "example.com"
            }
        }
        mock_identify_existing_config_file.return_value = copy.deepcopy(
            static_client_discovery_info)

        dynamic_discovery_issuer = "example2.com"
        new_gui_config = create_new_configuration_dict()
        new_gui_config = set_dynamic_discovery_issuer_config_gui_structure(
            dynamic_discovery_issuer, new_gui_config)
        config_file_dict = convert_config_gui_structure(new_gui_config,
                                                        0,
                                                        "id",
                                                        True,
                                                        conf=server_config)

        assert "srv_discovery_url" in config_file_dict
        assert dynamic_discovery_issuer == config_file_dict[
            'srv_discovery_url']

        with pytest.raises(KeyError):
            config_file_dict['provider_info']
    def test_overwrite_dynamic_with_static_discovery(self, mock_identify_existing_config_file, mock_generate_static_input_fields):
        server_config = self._setup_server_config()
        dynamic_discovery_issuer = "example2.com"
        static_client_discovery_info = {"srv_discovery_url": dynamic_discovery_issuer}
        mock_identify_existing_config_file.return_value = copy.deepcopy(static_client_discovery_info)

        default_static_discovery_value = "example"
        mock_generate_static_input_fields.return_value = _generate_static_input_fields(default_static_discovery_value)
        new_gui_config = create_new_configuration_dict()
        new_gui_config['fetchStaticProviderInfo']['showInputFields'] = True
        config_file_dict = convert_config_gui_structure(new_gui_config, 0, "id", True, server_config)

        assert config_file_dict['provider_info']
        with pytest.raises(KeyError):
            config_file_dict['srv_discovery_url']
Example #7
0
    def test_overwrite_static_with_dynamic_discovery(self, mock_identify_existing_config_file):
        server_config = self._setup_server_config()
        static_client_discovery_info = {"provider_info": {"jwks_uri": "example.com/jwks",
                                                          "authorization_endpoint": "example.com/auth",
                                                          "response_types_supported": "response_types_supported",
                                                          "id_token_signing_alg_values_supported": ['alg'],
                                                          "subject_types_supported": ['subject_type'],
                                                          "issuer": "example.com"}}
        mock_identify_existing_config_file.return_value = copy.deepcopy(static_client_discovery_info)

        dynamic_discovery_issuer = "example2.com"
        new_gui_config = create_new_configuration_dict()
        new_gui_config = set_dynamic_discovery_issuer_config_gui_structure(dynamic_discovery_issuer, new_gui_config)
        config_file_dict = convert_config_gui_structure(new_gui_config, 0, "id", True, conf=server_config)

        assert "srv_discovery_url" in config_file_dict
        assert dynamic_discovery_issuer == config_file_dict['srv_discovery_url']

        with pytest.raises(KeyError):
            config_file_dict['provider_info']