<commit_before>require "rails_helper"

RSpec.describe "Registration requests", :type => :request do
  before(:all) do 
    User.delete_all
    Auth::Client.delete_all
    @u = User.new(attributes_for(:user_confirmed))
    @u.save
    @c = Auth::Client.new(:resource_id => @u.id, :api_key => "test")
    @c.redirect_urls = ["http://www.google.com"]
    @c.app_ids << "test_app_id"
    @c.path = "omniauth/users/"
    @c.versioned_create
    @u.client_authentication["test_app_id"] = "test_es"
    @u.save
    @ap_key = @c.api_key
    @headers = { "CONTENT_TYPE" => "application/json" , "ACCEPT" => "application/json"}
  end


  context " -- google_oauth_2 ", :oauth => true do 
    it " -- json request to callback url with state built from json encoded client, works --" do 
    OmniAuth.config.test_mode = false
    Rails.application.env_config["omniauth.model"] = "omniauth/users/"

    post google_oauth2_omniauth_callback_url(:access_token => "<PASSWORD>", :state => {:api_key => @c.api_key, :current_app_id => @c.app_ids[0], :path => @c.path}.to_json),OmniAuth.config.mock_auth[:google_oauth2],@headers
    end

  end

  
  
  ###THIS TEST IS ONLY APPLICABLE TO FACEBOOK , BECAUSE WE CAN SHARE THE AUTHENTICATION TOKEN BETWEEN THE ANDROID APP AND THE SERVER.

  ##THE ONLY THING IS THAT IN CASE WE ALREADY HAVE A DESKTOP AUTHENTICATION FOR THIS USER, WITH AN ACCESS TOKEN, AND THEN HE TRIES TO AUTHENTICATE WITH ANDROID, OUR SERVER WILL REPLY SAYING THERE IS ALREADY AN ACCOUNT WITH THIS EMAIL.

  ##HOW TO HANDLE THIS SITUATION.
  ##provided that the uid and provider is the same he will simply get signed in.
  ##in that case, he will behave like a signed in user, and we can use the new authentication token, instead, which we are already doing.
  ##so we just need to simulate this one request.
    
  ##for the google tests we have to be able to call the test from java.




	  

end<commit_msg>understood different modalities of oauth on fb and google<commit_after>require "rails_helper"

RSpec.describe "Registration requests", :type => :request do
  before(:all) do 
    User.delete_all
    Auth::Client.delete_all
    @u = User.new(attributes_for(:user_confirmed))
    @u.save
    @c = Auth::Client.new(:resource_id => @u.id, :api_key => "test")
    @c.redirect_urls = ["http://www.google.com"]
    @c.app_ids << "test_app_id"
    @c.path = "omniauth/users/"
    @c.versioned_create
    @u.client_authentication["test_app_id"] = "test_es"
    @u.save
    @ap_key = @c.api_key
    @headers = { "CONTENT_TYPE" => "application/json" , "ACCEPT" => "application/json"}
  end


  context " -- google_oauth_2 ", :oauth => true do
    ###THERE ARE BASICALLY THREE POSSIBILITIES:
    ##1. PARAMS CONTAIN "CODE" - THIS IS DONE WHEN YOU HAVE ASKED THE USER ON AN ANDROID APP, TO GIVE OFFLINE ACCESS. YOU WILL HAVE TO POST THIS CODE TO THE CALLBACK URL, AND THIS SHOULD BE A JSON REQUEST.

    ##2. PARAMS CONTAIN "CODE" + "REDIRECT_URL" - THIS IS THE USUAL WEB APPLICATION FLOW.

    ##3. PARAMS CONTAIN "ACCESS_TOKEN" - THIS IS WHEN WE HAVE ASKED USER ONLY FOR CERTAIN PERMISSIONS, AND SO NOT TOTAL SERVER-SIDE API ACCESS, AND SO IT RETURNS ONLY A USER_ID_TOKEN, WHICH HAS TO BE PASSED INTO THE CALLBACK UNDER THE PARAM_NAME OF ACCESS_TOKEN.

    ##WE HAVE TO TEST POSSIBLITY ONE AND THREE.
    ##FROM THE ANDROID APP.

    it " -- json request to callback url with state built from json encoded client, works --" do 
    OmniAuth.config.test_mode = false
    Rails.application.env_config["omniauth.model"] = "omniauth/users/"

    post google_oauth2_omniauth_callback_url(:access_token => "<PASSWORD>", :state => {:api_key => @c.api_key, :current_app_id => @c.app_ids[0], :path => @c.path}.to_json),OmniAuth.config.mock_auth[:google_oauth2],@headers
    end

  end

  ##in case of facebook the app_id as long as it is same, then posting the code to the callback endpoint should work out.
    



	  

end
{'fraction_non_alphanumeric': 0.11230493732412382, 'fraction_numerical': 0.0028140189306728063, 'mean_word_length': 3.638196915776987, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7585248', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1305, 'n_words': 421}