예제 #1
0
get_google_access_token(){
		int rc=LR_PASS;
	char sOut[256]; // used by wi_EncodePlainToURL()

	rc=get_pJWTAssertion(); // into parameter pJWTAssertion used by this function.
	if( rc != LR_PASS ){ return rc; } // No input data to process.

		if( stricmp("Token",LPCSTR_RunType ) == FOUND ){ // "Token" or "TOKEN" specified in Run-time Attribute "RunType" or command line option "-RunType".
			wi_startPrintingTrace();
		    lr_output_message(">> RunType=\"%s\". JWT=%s."
					,LPCSTR_RunType 
					,lr_eval_string("{pJWTAssertion}")
					);
			wi_stopPrinting();
			return LR_PASS;
		}

	    web_add_header("Content-Type","application/x-www-form-urlencoded");
	    web_add_header("X-Frame-Options","deny"); // to protect against drag'n drop clickjacking attacks in older browsers.
	    web_reg_save_param_ex("ParamName=pAccessToken","LB=\"access_token\" : \"","RB=\"",SEARCH_FILTERS,"Scope=body",LAST);

	    // Example: "Body=grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion={pJWTAssertion}",
	    wi_EncodePlainToOAuth("grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=",sOut );
	    lr_save_string(sOut,"pJWTAssertion_request");
			wi_startPrintingTrace();
		    lr_output_message(">> sOut=\"%s\"."
					,lr_eval_string("{pJWTAssertion_request}")
					);
			wi_stopPrinting();
				
		// TODO: 15. If you want to, change the transaction name suffix for access authorization requests.
		sprintf( 	   tempString1, "%s_1access", lr_eval_string("{pTransSequence}") );
		lr_save_string(tempString1,"pTransName");
	    wi_start_transaction();
	    // web_rest("Token",
	    web_custom_request("Token",
                       "URL=https://accounts.google.com/o/oauth2/token",
                       "Method=POST",
                       //"ResType=JSON",
                       "Body={pJWTAssertion_request}{pJWTAssertion}",
                       LAST);
                       // The %3A are urlencoded from colons. (but %2D for the dash causes an "Invalid request" response):
                       // "Body=grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion={pJWTAssertion}",
                       // 		Common name for "jwt-bearer" is JWT Bearer Token Grant Type Profile for OAuth 2.0
                       // 		Defined at http://tools.ietf.org/html/draft-ietf-oauth-jwt-bearer-04
	    rc = wi_end_transaction();
	    // "Error -27796: Could not resolve address of hot accounts.google.com" is issued if there in no internet connection.
	    // Google API does not issue "error_description" such as "Audience validation failed".

		/* The response should look something like:
		{
  			"access_token" : "1/_5pUwJZs9a545HSeXXXXXuNGITp1XtHhZXXxxyyaacqkbc",
			"token_type" : "Bearer",
			"expires_in" : 3600
		}
		*/
		
    return rc;
} // get_google_access_token()
예제 #2
0
wi_start_transaction(){
	static float	floatThinkTimeSecs; // defined in wi_set_Think_Time().

	// lr_save_string( strTransName,"pTransName" ); // defined in Action().
	lr_start_transaction(lr_eval_string("{pTransName}"));
	
	// lr_get_transaction_duration(lr_eval_string("{pTransName}"));
	web_reg_save_param_ex("ParamName=pJSONResponse","LB={","RB=}", "Notfound=warning", LAST); // captures JSON

	lr_think_time( floatThinkTimeSecs );
		
    return LR_PASS;
} // wi_start_transaction
예제 #3
0
Action()
{

    lr_start_transaction("MTK_Web_010_OpenHomePage");

//	web_add_cookie("external_no_cache=1; DOMAIN=89.238.153.133");

    web_url("index.php",
            "URL=http://89.238.153.133/index.php",
            "Resource=0",
            "RecContentType=text/html",
            "Referer=",
            "Snapshot=t1.inf",
            "Mode=HTML",
            EXTRARES,
            LAST);

    lr_end_transaction("MTK_Web_010_OpenHomePage",LR_AUTO);

    lr_think_time(5);



    for (i=1; i<=5; i++)
    {
        lr_save_string(lr_eval_string("{pSearchTerm}"), "sSearchTerm");

        web_reg_save_param_ex(
            "ParamName=cFirstLink",
            "LB=<li class=\"item first\">\n                <a href=\"http:\/\/89.238.153.133\/index.php\/",
            "RB=\"",
            "NotFound=warning",
            SEARCH_FILTERS,
            LAST);

        lr_start_transaction("MTK_Web_020_ProductSearch");

        web_url("result",
                "URL=http://89.238.153.133/index.php/catalogsearch/result/?q={sSearchTerm}",
                "Resource=0",
                "RecContentType=text/html",
                "Referer=http://89.238.153.133/index.php",
                "Snapshot=t4.inf",
                "Mode=HTML",
                EXTRARES,
                LAST);

        lr_end_transaction("MTK_Web_020_ProductSearch",LR_AUTO);

        lr_think_time(5);

        lr_start_transaction("MTK_Web_030_SelectItem");

        web_url("ItemSelection",
                "URL=http://89.238.153.133/index.php/{cFirstLink}",
                "Resource=0",
                "RecContentType=text/html",
                "Referer=http://89.238.153.133/index.php/catalogsearch/result/?q={sSearchTerm}",
                "Snapshot=t5.inf",
                "Mode=HTML",
                EXTRARES,
                LAST);

        lr_end_transaction("MTK_Web_030_SelectItem",LR_AUTO);

        lr_think_time(5);
    }

    web_reg_save_param_ex(
        "ParamName=cPageURLs",
        "LB=<a href=\"",
        "RB=\"",
        "Ordinal=ALL",
        SEARCH_FILTERS,
        LAST);

    lr_start_transaction("MTK_Web_040_ReturnHome");

    web_url("index.php_2",
            "URL=http://89.238.153.133/index.php/",
            "Resource=0",
            "RecContentType=text/html",
            "Referer=http://89.238.153.133/index.php/",
            "Snapshot=t20.inf",
            "Mode=HTML",
            LAST);

    lr_end_transaction("MTK_Web_040_ReturnHome",LR_AUTO);

    lr_think_time(5);

    for (i=1; i<=10; i++)
    {

        web_reg_save_param_ex(
            "ParamName=cPageURLs",
            "LB=<a href=\"",
            "RB=\"",
            "Ordinal=ALL",
            SEARCH_FILTERS,
            LAST);

        lr_save_string(lr_paramarr_random( "cPageURLs" ),"cRandURL");

        lr_start_transaction("MTK_Web_050_SelectRandomLink");

        web_url("RandURL",
                "URL={cRandURL}",
                "Resource=0",
                "RecContentType=text/html",
                "Referer=http://89.238.153.133/index.php/",
                "Snapshot=t21.inf",
                "Mode=HTML",
                EXTRARES,
                LAST);

        lr_end_transaction("MTK_Web_050_SelectRandomLink",LR_AUTO);

        lr_think_time(5);
    }

    return 0;
}
예제 #4
0
get_google_short_url_qrcode(){
	int rc=0;
		char            strFileName[256]; // largest size of file.
		char           *szBuf;
		unsigned long   nLength;

	if( stricmp("Y",LPCSTR_SaveImageYN ) == FOUND ){ // Run-time Attribute "SaveImageYN" or command line option "-SaveImageYN"
	   // continue if SaveImageYN was specified with Y
	}else{
		return LR_PASS;
	}

		set_pShortHostKey_from_url( lr_eval_string("{pShortURL}") ); // from get_google_short_url()
			//wi_startPrintingTrace();
			//lr_output_message(">> pShortHostKey=\"%s\"." ,lr_eval_string("{pShortHostKey}") );
			//wi_stopPrinting();

		// For shortened URL http://goo.gl/AC4IW", details are at http://goo.gl/#analytics/goo.gl/AC4IW/all_time
		// {pShortHostKey}=AC4IW in example: URL http://goo.gl/AC4IW.qr redirects to 
		// The QR code impage at http://chart.googleapis.com/chart?cht=qr&chs=100x100&choe=UTF-8&chld=H|0&chl=http://goo.gl/AC4IW
		web_reg_save_param_ex("ParamName=pImage", "LB=\r\n\r\n", "RB=\"",  "Notfound=warning", LAST); // The \r\n\r\n is to begin capture after the two blank lines between HTTP header and body.
		web_reg_save_param_ex("ParamName=pImage_len", "LB=Content-Length: ", "Notfound=warning", "RB=\r\n", LAST);

		sprintf(       tempString1, "%s_3image", lr_eval_string("{pTransSequence}") );
		lr_save_string(tempString1,"pTransName");
	    wi_start_transaction();
	    
    // This URL was obtained from the DNS-level redirect in the HTML header in response to request for .qr, such as:
    // The document has moved <A 
    //        HREF="http://chart.googleapis.com/chart?cht=qr&amp;chs=150x150&amp;choe=UTF-8&amp;chld=H&amp;chl=http://goo.gl/x6wUIS">here</A>.\n
    	// &amp; needs to be coverted to & character in URLs.
    	
		// WARNING: The 150x150 in this URL may change over time as more characters are needed for uniqueness.
		// Previously,  100x100 was being returned:
		//    "URL={pShortURL}.qr",
		web_url("imagefile",
	        "URL=http://chart.googleapis.com/chart?cht=qr&chs=150x150&choe=UTF-8&chld=H&chl={pShortURL}",
	        "Resource=1",
	        "RecContentType=image/png",
	        "Snapshot=t1.inf",
	        LAST);
		// FIXME: File created has black box at bottom.
	
	    rc = wi_end_transaction();

		// strFileName=wi_define_FileName():
		lr_save_datetime("%Y%m%d%H%M%S", DATE_NOW, "pYMDHMS"); // YYMMDDHHMMSS (12 char), no micro seconds
		sprintf(strFileName, "%s%s_%d_T%s_%s_%s.png"
		        ,lr_eval_string("{pImageFilePath}")
				,global_unique_id
				,iActionIterations
				,lr_eval_string("{pYMDHMS}")
		        ,lr_eval_string("{pShortHostKey}")
		        ,lr_eval_string("{pImage_len}")
		       );

		lr_eval_string_ext("{pImage}", strlen("{pImage}"), &szBuf, &nLength, 0, 0, -1);
		// lr_eval_string_ext( in_str, in_len,    pointer out_str, out_len, Reserved for future use. 
		if( nLength <= 0 ){
			lr_error_message(">> No image returned for %s.",strFileName);
		}else{
			if( wi_WriteDataToFile(strFileName, szBuf, nLength) == LR_PASS ){
				wi_startPrintingInfo();
				lr_output_message(">> QRcode_image file created at \"%s\".",strFileName);
				wi_stopPrinting();
			   	// TODO: 23. Remember after runs to clear out the files to an archive filer.
			}else{
				wi_startPrintingError();
				lr_error_message(">>> QRcode_image file NOT created at \"%s\".",strFileName);
				wi_stopPrinting();
			}
		}
	return rc;
} // retrieve_pShortURL_qrcode()
예제 #5
0
get_google_short_url(){
    
	// About this call: https://developers.google.com/url-shortener/v1/getting_started
	// Forum on this:   https://groups.google.com/forum/#!forum/google-url-shortener

	int rc=LR_PASS;
	int	bURLtoShorten_success=LR_PASS;

	rc=get_long_url_to_shorten();
	if( rc != LR_PASS ){ return rc; } // No input data to process.
	
	// Define the URL Shortener API Scope to Google:
	lr_save_string("https://www.googleapis.com/auth/urlshortener","pServiceScope");
					// Other Google API FAQ scopes: https://developers.google.com/gdata/faq#AuthScopes

	sprintf(       tempString1, "%s_access", lr_eval_string("{pTransSequence}") );
	lr_save_string(tempString1,"pTransName");
	rc=get_google_access_token();
	if( rc != LR_PASS ){ return rc; } // No input data to process.

	if( stricmp("NoOp",LPCSTR_RunType ) == FOUND ){ // "NoOp" or "NOOP" specified in Run-time Attribute "RunType" or command line option "-RunType".
		wi_startPrintingInfo();
		lr_output_message(">> RunType=\"%s. JWT=%s."
				,LPCSTR_SaveImageYN
				,lr_eval_string("{pJWTAssertion}")
				);
		wi_stopPrinting();
		return LR_PASS;
	}

		// Using parameter file "URLtoShorten.dat" containing parmeter "pURLtoShorten":
		web_reg_save_param_ex("ParamName=pLongURL","LB=\"longUrl\": \"","RB=\"",SEARCH_FILTERS,"Scope=body",LAST);	// the long  URL input to API server.
		web_reg_save_param_ex("ParamName=pShortURL","LB=\"id\": \"","RB=\"",SEARCH_FILTERS,"Scope=body",LAST); 		// the short URL output from server.

		// WARNING: Google does not check if there is a short code already generated for the URL before generating another one (which bit.ly does).
		web_add_header("Authorization", lr_eval_string("Bearer {pAccessToken}"));
	    web_add_header("Content-Type", "application/json");

		// TODO: 18. If you want to, change the transaction name suffix for shortenend url requests.
		sprintf( 	   tempString1, "%s_2shorturl", lr_eval_string("{pTransSequence}") );
		lr_save_string(tempString1,"pTransName");
	    wi_start_transaction();
	    web_custom_request("Shorten",
                       "URL=https://www.googleapis.com/urlshortener/v1/url",
                       "Method=POST",
                       "Body={\"longUrl\": \"{pURLtoShorten}\"}",
                       LAST);    
					// This code is the C equivalent of the Java at https://developers.google.com/api-client-library/java/apis/urlshortener/v1    
		// Google docs say output should look like this:
		//	{
		//		"kind": "urlshortener#url",\n
		//		"id": "http://goo.gl/jQVbkn",\n
		//		"longUrl": "http://www.hp.com/"\n
		//	}

		rc = wi_end_transaction();

		if( rc == LR_PASS ){
			bURLtoShorten_success=LR_PASS;
			nURLtoShorten_done++; // increment.
		}
		
		wi_startPrintingDebug();
	    lr_output_message(">> done=%d LongURL=%s to pShortURL=%s, seconds=%8.2f under %s."
		        ,nURLtoShorten_done 
				,lr_eval_string("{pLongURL}")
				,lr_eval_string("{pShortURL}")
				,floatHttpMilliseconds
				,lr_eval_string("{pRunConditions}")
				);
		wi_stopPrinting();
	
	#ifdef USE_VTS
	update_shorturl_in_VTS();
	#endif // USE_VTS

	#ifdef GEN_QR
	if( bURLtoShorten_success == LR_PASS ){
		// TODO: 19. Customize your own transaction name for calling get_google_short_url_qrcode().
		lr_save_string("get_google_short_url_qrcode","pTransName"); 
		get_google_short_url_qrcode(); // using pShortURL and pImageFilePath, depending on command flag LPCSTR_SaveImageYN.
	}
	#endif // GEN_QR

	return rc;
} // get_google_short_url()
WorkOutPlanPurchase()
{
	
/*Correlation comment - Do not change!  Original value='3sCnTcDtwsZPf9vlj0rpD7akf8tqkJ+cmjiSZOGI3LcuQkPylwLVUnv9wGCArP7fsctxWzcYxxZdiLyl1Xf9NA==' Name ='authenticity_token_2' Type ='Manual'*/
	web_reg_save_param_regexp("ParamName=authenticity_token_2","RegExp=\\ content=\"(.*?)\"\\ ","Ordinal=2",SEARCH_FILTERS,"Scope=Body","IgnoreRedirections=No",LAST);
	
	
	lr_start_transaction("EMPLYE_0018_Shop_For_Plans");

	web_link("Shop for plans Browse plans from carriers in the DC Health Care Exchange.", 
		"Text=Shop for plans Browse plans from carriers in the DC Health Care Exchange.", 
		"Snapshot=t24.inf", 
		LAST);

	lr_end_transaction("EMPLYE_0018_Shop_For_Plans",LR_AUTO);
	
	lr_think_time(10);
	
/*********************************************************************************************************************************************************************/	

/*Correlation comment - Do not change!  Original value='55c40cf669702d3238000000' Name ='plan_shoppings' Type ='Manual'*/
	web_reg_save_param_regexp("ParamName=plan_shoppings","RegExp=plan_shoppings/(.*?)\\\r\\\n",SEARCH_FILTERS,"Scope=Headers","IgnoreRedirections=No","RequestUrl=*/create*",LAST);

/*Correlation comment - Do not change!  Original value='5453a543791e4bcd33000007' Name ='plan_id' Type ='Manual'*/
//	web_reg_save_param_regexp("ParamName=plan_id","RegExp=plan_id=(.*?)\">Select\\ Plan",SEARCH_FILTERS,"Scope=Body","IgnoreRedirections=Yes","RequestUrl=*/55c40cf669702d3238000000*",	LAST);

	web_reg_save_param_ex("ParamName=plan_id", "LB=plan_id=", "RB=\">Select Plan", SEARCH_FILTERS, LAST );
	
	/*Correlation comment - Do not change!  Original value='3sCnTcDtwsZPf9vlj0rpD7akf8tqkJ+cmjiSZOGI3LcuQkPylwLVUnv9wGCArP7fsctxWzcYxxZdiLyl1Xf9NA==' Name ='authenticity_token_2' Type ='Manual'*/
	web_reg_save_param_regexp("ParamName=authenticity_token_3","RegExp=\\ content=\"(.*?)\"\\ ","Ordinal=2",SEARCH_FILTERS,"Scope=Body","IgnoreRedirections=No",LAST);
	
/*********************************************************************************************************************************************************************/	
	lr_think_time(10);
		
	lr_start_transaction("EMPLYE_0019_Select_Plan_Continue_{plan_count}");

	web_submit_data("create",
		"Action=http://{enrollAppLandingPage}/group_selection/create",
		"Method=POST",
		"TargetFrame=",
		"RecContentType=text/html",
		"Referer=http://{enrollAppLandingPage}/group_selection/new?employee_role_id={employee_role_id}&person_id={person_id}",
		"Snapshot=t37.inf",
		"Mode=HTML",
		ITEMDATA,
		"Name=utf8", "Value=?", ENDITEM,
		"Name=authenticity_token", "Value={authenticity_token_2}", ENDITEM,
		"Name=person_id", "Value={person_id}", ENDITEM,
		"Name=employee_role_id", "Value={employee_role_id}", ENDITEM,
		"Name=coverage_household_id", "Value=", ENDITEM,
		"Name=family_member_ids[0]", "Value={Spouse}", ENDITEM,
		"Name=family_member_ids[1]", "Value={Child_1}", ENDITEM,
		"Name=family_member_ids[2]", "Value={Child_2}", ENDITEM,
		"Name=family_member_ids[3]", "Value={Child_3}", ENDITEM,
		LAST);
	
	lr_end_transaction("EMPLYE_0019_Select_Plan_Continue_{plan_count}",LR_AUTO);

	lr_think_time(10);

/*********************************************************************************************************************************************************************/

	/*Correlation comment - Do not change!  Original value='3sCnTcDtwsZPf9vlj0rpD7akf8tqkJ+cmjiSZOGI3LcuQkPylwLVUnv9wGCArP7fsctxWzcYxxZdiLyl1Xf9NA==' Name ='authenticity_token_2' Type ='Manual'*/
	web_reg_save_param_regexp("ParamName=authenticity_token_4","RegExp=\\ content=\"(.*?)\"\\ ","Ordinal=2",SEARCH_FILTERS,"Scope=Body","IgnoreRedirections=No",LAST);
	
/*********************************************************************************************************************************************************************/	

	lr_start_transaction("EMPLYE_0020_Click_Select_Plan");

	web_submit_data("thankyou",
		"Action=http://{enrollAppLandingPage}/insured/plan_shoppings/{plan_shoppings}/thankyou?change_plan=&plan_id={plan_id}",
		"Method=POST",
		"TargetFrame=",
		"RecContentType=text/html",
		"Referer=http://{enrollAppLandingPage}/insured/plan_shoppings/{plan_shoppings}",
		"Snapshot=t38.inf",
		"Mode=HTML",
		ITEMDATA,
		"Name=_method", "Value=post", ENDITEM,
		"Name=authenticity_token", "Value={authenticity_token_3}", ENDITEM,
		LAST);
	
	lr_end_transaction("EMPLYE_0020_Click_Select_Plan",LR_AUTO);
	
	lr_think_time(10);
/*********************************************************************************************************************************************************************/

	/*Correlation comment - Do not change!  Original value='3sCnTcDtwsZPf9vlj0rpD7akf8tqkJ+cmjiSZOGI3LcuQkPylwLVUnv9wGCArP7fsctxWzcYxxZdiLyl1Xf9NA==' Name ='authenticity_token_2' Type ='Manual'*/
	web_reg_save_param_regexp("ParamName=authenticity_token_4","RegExp=\\ content=\"(.*?)\"\\ ","Ordinal=2",SEARCH_FILTERS,"Scope=Body","IgnoreRedirections=No",LAST);
	
/*********************************************************************************************************************************************************************/	
	
	lr_start_transaction("EMPLYE_0021_Purchase");

	web_submit_data("checkout", 
		"Action=http://{enrollAppLandingPage}/insured/plan_shoppings/{plan_shoppings}/checkout?change_plan=change_plan&plan_id={plan_id}", 
		"Method=POST", 
		"RecContentType=text/html", 
		"Referer=http://{enrollAppLandingPage}/insured/plan_shoppings/{plan_shoppings}/thankyou?change_plan=change_plan&plan_id={plan_id}", 
		"Snapshot=t27.inf", 
		"Mode=HTML", 
		ITEMDATA, 
		"Name=_method", "Value=post", ENDITEM, 
		"Name=authenticity_token", "Value={authenticity_token_4}", ENDITEM, 
		LAST);

	lr_end_transaction("EMPLYE_0021_Purchase",LR_AUTO);

	lr_think_time(10);

	// Add Token Explicitly
	
	web_add_header ("X-CSRF-Token", "{authenticity_token_5}");
/*********************************************************************************************************************************************************************/

	/*Correlation comment - Do not change!  Original value='3sCnTcDtwsZPf9vlj0rpD7akf8tqkJ+cmjiSZOGI3LcuQkPylwLVUnv9wGCArP7fsctxWzcYxxZdiLyl1Xf9NA==' Name ='authenticity_token_2' Type ='Manual'*/
	web_reg_save_param_regexp("ParamName=authenticity_token_4","RegExp=\\ content=\"(.*?)\"\\ ","Ordinal=2",SEARCH_FILTERS,"Scope=Body","IgnoreRedirections=No",LAST);
	
/*********************************************************************************************************************************************************************/	
	
	lr_start_transaction("EMPLYE_0022_Continue");

	web_link("My Account", 
		"Text=My Account", 
		"Snapshot=t28.inf", 
		LAST);

	lr_end_transaction("EMPLYE_0022_Continue",LR_AUTO);

	lr_think_time(10);
		
	return 0;
}