AllureRestAssured , how to ignore logging headers - rest-assured

I am using rest-assured and allureRestAssured for testing api ,
given().header("Content-Type", "application/json")
.header("key", key()).filter(new AllureRestAssured())
.body(body.toString())
.post(baseURI);
Problem here is its logged headers also , which contains auth key , which I dont want to be exposed in report generated , how can I ignore that .

You can extend the AllureRestAssured filter and override it. There is the private method toMapConverter I add it to my implementation. I just remove by Key what I don't want to show in the report.
private static Map<String, String> toMapConverter(final Iterable<? extends NameAndValue> items) {
final Map<String, String> result = new HashMap<>();
items.forEach(h -> result.put(h.getName(), h.getValue()));
result.remove("key");
return result;
}

Related

Cannot parse id for appbundles using Design Automation SDK

Here I am again trying to use the Design Automation SDK and I get this error when I try to retrieve bundle aliases, versions or other information that require the id.
I am testing that using one of the existing appbundles available...
public static async Task<dynamic> GetAppBundleVersionsAsync(ForgeService service, Token token, string id)
{
try
{
if (token.ExpiresAt < DateTime.Now)
token = Get2LeggedToken();
AppBundlesApi appBundlesApi = new AppBundlesApi(service);
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("Authorization", "Bearer " + token.AccessToken);
headers.Add("content-type", "application/json");
var aliases = await appBundlesApi.GetAppBundleVersionsAsync(id, null, null, headers);
return aliases;
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Error : {0}", ex.Message));
return null;
}
}
Almost thinking to go to my previous RestSharp implementation :)
There are 2 kinds of IDs:
Fully qualified (string in format owner.name+alias)
Unqualified (just name)
You are trying to list versions of your own AppBundle, so you need to use Unqualified. It seems your ID is fully qualified form.
For more info look at API documentation description of endpoint id parameter you are using https://forge.autodesk.com/en/docs/design-automation/v3/reference/http/design-automation-appbundles-id-versions-GET/#uri-parameters

Post Request via JxBrowser does not hand over data

I try a POST Request with the new JxBrowser Version. Unfortunately the data in the body is not handed over.
I guess I am just not using JxBrowser 7 properly.
GET Request does work.
// Post Request
protected void postRequestFromScout(JxBrowserEvent event) {
String url = event.getUrl();
Map<String, String> postData = event.getPostData();
getBrowser().navigation().loadUrl(LoadRequest.newBuilder()
.setUrl(url)
.setPostData(toPostDataString(postData))
.build());
}
// data in POST Request Body as String
protected String toPostDataString(Map<String, String> postData) {
StringBuilder sb = new StringBuilder();
for (Entry<String, String> entry : postData.entrySet()) {
sb
.append(entry.getKey())
.append("=")
.append(IOUtility.urlEncode(entry.getValue()))
.append("&");
}
sb.deleteCharAt(sb.length() - 1);
return sb.toString();
}
I obviously need to hand over the data in this way:
LoadUrlParams.newBuilder(url)
.postData(toPostDataString(postData))
.build();
As we are using a Compiler based on Java 7 in our Project, this is not a solution for me right now and I will check for another one if possible, but it surely works when used with Java 8.

Rest template fail sending apple verification data

I'm trying to validate from apple inapp purchase api using rest template and it fails. (works fine in postman). Postman collection: collection postman
How I can archive this using rest template? Is base64 encored data not allowed ?
` HttpHeaders httpHeaders = new HttpHeaders();
// httpHeaders.setContentType(MediaType.APPLICATION_JSON);
//httpHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add(Constant.PURCHASE.RECEIPT_DATA, purchase.getReceiptData());
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, httpHeaders);
ResponseEntity<String> postResponse = restTemplate.postForEntity(iosPurchaseService, request, String.class);`
You can use a object with following property to send the value you need to provide as the input of your API call instead of providing it in a MultiValueMap.
public class SomeObject implements Serializable {
private static final long serialVersionUID = 1L;
#JsonProperty("receipt-data")
private String receiptdata;
}
Then bind this object inside your controller as follows.
public void apiCall(#RequestBody SomeObject someObject) {
//Method 1
ResponseEntity<String> response1 = restTemplate.postForEntity("https://sandbox.itunes.apple.com/verifyReceipt", someObject,
String.class);
// or Method 2
ResponseEntity<String> response2 = restTemplate.exchange("https://sandbox.itunes.apple.com/verifyReceipt", HttpMethod.POST, new HttpEntity<>(someObject, null),
String.class);
}

Where can i find the debug information in zuul?

I want to use debugFilter in ZUUL. when i post param "debug=true" in query string, I can't find the debug info in my standard output.
Where can i find the debug information?
If you call api with param debug=true, debugging information will be accumulated into RequestContext with a key routingDebug. The value is List<String> type.
If you set the properties like below, debug info will be added into response-header - X-Zuul-Debug-Header.
zuul.include-debug-header=true
As far as I know, this information is not printed out to standard out as default.
Instead, you can easily access this info via com.netflix.zuul.context.Debug.getRoutingDebug().
You can make your own post filter to print out this info easily like below.
#Override
public boolean shouldFilter() {
return Debug.debugRouting();
}
#Override
public Object run() {
String debug = convertToPrettyPrintString(Debug.getRoutingDebug());
log.info("Filter Debug Info = \n{}", debug);
// or System.out.println(...)
return null;
}
private String convertToPrettyPrintString(List<String> filterDebugList) {
return filterDebugList.stream()
.map(s -> s.startsWith("{") ? "\t" + s : s)
.collect(Collectors.joining("\n"));
}

Memory overusage in Play! Framework method call

In one of my Controllers, I have multiple URLs that will ultimately render in the same way. For example, this method scans the network on which the server resides, caches a String representation of each connected device and each device listening on a specific port, and then sends that information to another method to render:
public static void networkScan(String networkTarget, String port)
{
//These two lists will never have more than 256 total entries
List<InetSocketAddress> listeningDevices;
Map<String, String> allDevices;
...Logic for discovering network devices...
//Store the results in a cache, for history preservation in the browser
Cache.set(session.getId() + "listeningDevices", listeningDevices);
Cache.set(session.getId() + "allDevices", allDevices);
showScan(listeningDevices, allDevices);
}
public static void showScan(List<InetSocketAddress> listeningDevices, Map<String, String> allDevices)
{
render(listeningDevices, allDevices);
}
public static void getCachedScan()
{
List<InetSocketAddress> listeningDevices = (List<InetSocketAddress>)Cache.get(session.getId() + "listeningDevices");
Map<String, String> allDevices = (Map<String, String>)Cache.get(session.getId() + "allDevices");
if(listeningDevices == null)
listeningDevices = new ArrayList<InetSocketAddress>();
if(allDevices == null)
allDevices = new TreeMap<String, String>();
renderScan(listeningDevices, allDevices);
}
Doing it this way results in Play doing some weird array copying that ends up taking infinite memory. If I were to change my call of showScan() to simply render() and create a view with the name networkScan.html, it all works just fine, no memory bugs.
I have several other methods that also use showScan, based on different caching settings. I don't want lots of views that are all essentially copies of each other, so I'm trying to go through just one method with one corresponding view.
This won't work:
showScan(listeningDevices, allDevices);
}
public static void showScan(List<InetSocketAddress> listeningDevices, Map<String, String> allDevices)
{
as play will serialize listeningDevices + allDevices to Strings and tries to build a url out of it.
either directly render the results in networkScan() or store the contents in the cache under a specific key
like you already do and then do something like
public static void networkScan(String networkTarget, String port)
{
//These two lists will never have more than 256 total entries
List<InetSocketAddress> listeningDevices;
Map<String, String> allDevices;
...Logic for discovering network devices...
//Store the results in a cache, for history preservation in the browser
Cache.set(session.getId() + "listeningDevices", listeningDevices);
Cache.set(session.getId() + "allDevices", allDevices);
showScan(session.getId());
}
public static void showScan(String sessionId)
{
List<InetSocketAddress> listeningDevices = Cache.get(sessionId + "listeningDevices");
Map<String, String> allDevices = Cache.get(sessionId + "allDevices");
render(listeningDevices, allDevices);
}
Turns out that calling an action method creates a redirect event, which resulted in all sorts of copying objects into URLs. I still don't understand how that mushroomed into using over a gigabyte of memory for a collection of Strings that rarely numbered above 100, and never above 256, but I found a way of avoiding the redirect event.
As I was directed to do in an answer on Google Groups, I made use of the #Util interceptor on the showScan method:
#Util
public static void showScan(List<InetSocketAddress> listeningDevices, Map<String, String> allDevices)
{
renderTemplate("Admin/showScan.html", listeningDevices, allDevices);
}
Marking a method with #Util unfortunately makes it use the template of the calling method, but the call to renderTemplate() allows me to use a single template that I specify.

Resources