<commit_before>require 'json'
require 'chef_zero/rest_base'

module ChefZero
  module Endpoints
    # /system_recovery
    class SystemRecoveryEndpoint < RestBase
      def post(request)
        request_json = JSON.parse(request.body, :create_additions => false)
        name = request_json['username']
        password = request_json['password']
        user = get_data(request, request.rest_path[0..-2] + ['users', name])
        user = JSON.parse(user, :create_additions => false)
        user = DataNormalizer.normalize_user(user, name, 'username')
        if !user['recovery_authentication_enabled']
          raise RestErrorResponse.new(403, "Only users with recovery_authentication_enabled=true may use /system_recovery to log in")
        end
        if user['password'] != password
          raise RestErrorResponse.new(401, "Incorrect password")
        end

        json_response(200, user)
      end
    end
  end
end
<commit_msg>Get principals endpoint passing oc_chef_pedant<commit_after>require 'json'
require 'chef_zero/rest_base'

module ChefZero
  module Endpoints
    # /system_recovery
    class SystemRecoveryEndpoint < RestBase
      def post(request)
        request_json = JSON.parse(request.body, :create_additions => false)
        name = request_json['username']
        password = request_json['password']
        user = get_data(request, request.rest_path[0..-2] + ['users', name], :nil)
        if !user
          raise RestErrorResponse.new(403, "Nonexistent user")
        end

        user = JSON.parse(user, :create_additions => false)
        user = DataNormalizer.normalize_user(user, name, [ 'username' ])
        if !user['recovery_authentication_enabled']
          raise RestErrorResponse.new(403, "Only users with recovery_authentication_enabled=true may use /system_recovery to log in")
        end
        if user['password'] != password
          raise RestErrorResponse.new(401, "Incorrect password")
        end

        json_response(200, user)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.09653465346534654, 'fraction_numerical': 0.012376237623762377, 'mean_word_length': 3.0663983903420524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '410063', 'n_tokens_mistral': 596, 'n_tokens_neox': 576, 'n_words': 140}