<commit_before>class DynamicRegistrationSequence < SequenceBase

  title 'Dynamic Registration'

  description 'Verify that the server supports the OAuth 2.0 Dynamic Client Registration Protocol.'

  optional

  modal_before_run

  preconditions 'OAuth endpoints are necessary' do
    !@instance.oauth_authorize_endpoint.nil? && !@instance.oauth_token_endpoint.nil?
  end

  test 'Client registration endpoint secured by transport layer security',
    'https://tools.ietf.org/html/rfc7591',
    'The client registration endpoint MUST be protected by a transport layer security.' do

    skip 'TLS tests have been disabled by configuration.' if @disable_tls_tests
    assert_tls_1_2 @instance.oauth_register_endpoint
    warning {
      assert_deny_previous_tls @instance.oauth_register_endpoint
    }
  end

  test 'Client registration endpoint accepts POST messages',
    'https://tools.ietf.org/html/rfc7591',
    'The client registration endpoint MUST accept HTTP POST messages with request parameters encoded in the entity body using the "application/json" format.' do
    # params['redirect_uris'] = [params['redirect_uris']]
    # params['grant_types'] = params['grant_types'].split(',')
    headers = { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }

    params = {
      'client_name' => @instance.client_name,
      'initiate_login_uri' => "#{@instance.base_url}#{BASE_PATH}/#{@instance.id}/#{@instance.client_endpoint_key}/launch",
      'redirect_uris' => ["#{@instance.base_url}#{BASE_PATH}/#{@instance.id}/#{@instance.client_endpoint_key}/redirect"],
      'token_endpoint_auth_method' => 'none',
      'grant_types' => ['authorization_code'],
      'scope' => @instance.scopes,
    }

    binding.pry

    @registration_response = LoggedRestClient.post(@instance.oauth_register_endpoint, params.to_json, headers)
    @registration_response_body = JSON.parse(@registration_response.body)

  end

  test 'Registration endpoint does not respond with an error',
    'https://tools.ietf.org/html/rfc7591',
    'When an OAuth 2.0 error condition occurs, such as the client presenting an invalid initial access token, the authorization server returns an error response appropriate to the OAuth 2.0 token type.' do

      assert !@registration_response_body.has_key?('error') && !@registration_response_body.has_key?('error_description'),
                "Error returned.  Error: #{@registration_response_body['error']}, Description: #{@registration_response_body['error_description']}"

  end<commit_msg>Remove binding.pry.<commit_after>class DynamicRegistrationSequence < SequenceBase

  title 'Dynamic Registration'

  description 'Verify that the server supports the OAuth 2.0 Dynamic Client Registration Protocol.'

  optional

  modal_before_run

  preconditions 'OAuth endpoints are necessary' do
    !@instance.oauth_authorize_endpoint.nil? && !@instance.oauth_token_endpoint.nil?
  end

  test 'Client registration endpoint secured by transport layer security',
    'https://tools.ietf.org/html/rfc7591',
    'The client registration endpoint MUST be protected by a transport layer security.' do

    skip 'TLS tests have been disabled by configuration.' if @disable_tls_tests
    assert_tls_1_2 @instance.oauth_register_endpoint
    warning {
      assert_deny_previous_tls @instance.oauth_register_endpoint
    }
  end

  test 'Client registration endpoint accepts POST messages',
    'https://tools.ietf.org/html/rfc7591',
    'The client registration endpoint MUST accept HTTP POST messages with request parameters encoded in the entity body using the "application/json" format.' do
    # params['redirect_uris'] = [params['redirect_uris']]
    # params['grant_types'] = params['grant_types'].split(',')
    headers = { 'Accept' => 'application/json', 'Content-Type' => 'application/json' }

    params = {
      'client_name' => @instance.client_name,
      'initiate_login_uri' => "#{@instance.base_url}#{BASE_PATH}/#{@instance.id}/#{@instance.client_endpoint_key}/launch",
      'redirect_uris' => ["#{@instance.base_url}#{BASE_PATH}/#{@instance.id}/#{@instance.client_endpoint_key}/redirect"],
      'token_endpoint_auth_method' => 'none',
      'grant_types' => ['authorization_code'],
      'scope' => @instance.scopes,
    }

    @registration_response = LoggedRestClient.post(@instance.oauth_register_endpoint, params.to_json, headers)
    @registration_response_body = JSON.parse(@registration_response.body)

  end

  test 'Registration endpoint does not respond with an error',
    'https://tools.ietf.org/html/rfc7591',
    'When an OAuth 2.0 error condition occurs, such as the client presenting an invalid initial access token, the authorization server returns an error response appropriate to the OAuth 2.0 token type.' do

      assert !@registration_response_body.has_key?('error') && !@registration_response_body.has_key?('error_description'),
                "Error returned.  Error: #{@registration_response_body['error']}, Description: #{@registration_response_body['error_description']}"

  end
{'fraction_non_alphanumeric': 0.11326349080846017, 'fraction_numerical': 0.007906700929037358, 'mean_word_length': 4.704622322435175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4223213', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1406, 'n_words': 361}