Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure during execution, wrong config?? [DEBUG] typeof(BLeakConfig) !== "undefined" && BLeakConfig.loop[0].check() => false #49

Open
TheJsharper opened this issue Jul 18, 2019 · 1 comment

Comments

@TheJsharper
Copy link

TheJsharper commented Jul 18, 2019

H6 Do you have your opinion what was wrong?
  • Operator System: Windows 10
  • Python 3.7.2
  • mitmproxy version 4.0.1
  • config.js below

GitHub_reporting

// URL to the web application.
exports.url = "http://localhost:4200";
// Runs your program in a loop. Each item in the array is a `state`. Each `state` has a "check"
// function, and a "next" function to transition to the next state in the loop. These run
// in the global scope of your web app.
// BLeak assumes that the app is in the first state when it navigates to the URL. If you specify
// optional setup states, then it assumes that the final setup state transitions the web app to
// the first state in the loop.
// The last state in the loop must transition back to the first.
exports.loop = [
  // First state
  {
    // Return 'true' if the web application is ready for `next` to be run.
    check: function() {
      // Example: `group-listing` must be on the webpage
	    console.logt("====>", document.getElementsByTagName('app-root')[0]);
      return !!document.getElementsByTagName('app-root')[0];
    },
    // Transitions to the next state.
    next: function() {
      // Example: Navigate to the first thread
      //document.getElementById("thread-001").click();
	  document.location.assign("http://localhost:4200/settings")
    }
  },
  // Second (and last) state
  {
    check: function() {
      // Example: Make sure the body of the thread has loaded.
      return !!document.querySelector("app-shell mat-sidenav-container mat-sidenav-content td-layout-nav span span");
    },
    // Since this is the last state in the loop, it must transition back to the first state.
    next: function() {
      // Example: Click back to group listing
      document.querySelector("app-shell mat-sidenav-container mat-sidenav-content td-layout-nav span span").click();
    }
  }
];

// (Optional) Number of loop iterations to perform during leak detection (default: 8)
exports.iterations = 1;

// (Optional) An array of states describing how to login to the application. Executed *once*
// to set up the session. See 'config.loop' for a description of a state.
 /*exports.login = [
 {
    check: function() {
      // Return 'true' if the element 'password-field' exists.
      return !!document.getElementById('password-field');
    },
    next: function() {
      // Log in to the application.
      const pswd = document.getElementById('password-field');
      const uname = document.getElementById('username-field');
      const submitBtn = document.getElementById('submit');
      uname.value = 'spongebob';
      pswd.value = 'squarepants';
      submitBtn.click();
    }
  }
];*/
// (Optional) An array of states describing how to get from config.url to the first state in
// the loop. Executed each time the tool explicitly re-navigates to config.url. See
// config.loop for a description of states.
exports.setup = [

];
// (Optional) How long (in milliseconds) to wait for a state transition to finish before declaring an error.
// Defaults to 10 minutes
exports.timeout = 10* 60 *1000;//1000; //10 * 60 * 1000;
// (Optional) How long (in milliseconds) to wait between a check() returning 'true' and transitioning to the next step or taking a heap snapshot.
// Default: 1000
exports.postCheckSleep = 1000;
// (Optional) How long (in milliseconds) to wait between transitioning to the next step and running check() for the first time.
// Default: 0
exports.postNextSleep = 10;
// (Optional) How long (in milliseconds) to wait between submitting login credentials and reloading the page for a run.
// Default: 5000
//exports.postLoginSleep = 5000;
// (Optional) An array of numerical IDs identifying leaks with fixes in your code. Used to
// evaluate memory savings with different leak configurations and the effectiveness of bug fixes.
// In the code, condition the fix on $$$SHOULDFIX$$$(ID), or add logic to `exports.rewrite` (see below),
// and BLeak will run the web app with the fixes applied.
exports.fixedLeaks = [0, 1, 2];
// (Optional) Proxy re-write rule that runs in a Node.js environment, *not* in the browser.
// Lets you rewrite the web app's JavaScript/HTML/CSS to test bug fixes. Especially useful for evaluating
// fixes on web apps you do not control.
// Return a Node.js Buffer containing the replacement resource contents, or the original contents if not
// modifying.
exports.rewrite = function(url /* URL of the resource */,
                  type /* MIME type of resource */,
                  data /* Contents of resource, as a Node.js Buffer */,
                  fixes /* Array of numerical IDs corresponding to bug fixes that are active during the session (see fixedLeaks) */) {
  function hasFix(n) {
    return fixes.indexOf(n) !== -1;
  }
  // Example: Filter out non-JavaScript resources.
  if (type.indexOf("javascript") !== -1) {
    if (url.indexOf("19/common.js") !== -1) {
      let src = data.toString();
      // Example: Replace a specific string in `19/common.js` to fix bug 0.
      if (hasFix(0)) {
        src = src.replace(`window.addEventListener("scroll",a,!1)`, 'window.onscroll=a');
      }
      return Buffer.from(src, 'utf8');
    }
  }
  return data;
};
@TheJsharper TheJsharper changed the title Failure during execution, wrong config?? Failure during execution, wrong config?? [DEBUG] typeof(BLeakConfig) !== "undefined" && BLeakConfig.loop[0].check() => false Jul 18, 2019
@Sorwnqe
Copy link

Sorwnqe commented Jul 21, 2019

I think your mistake might be due to the url.

It doesn't seem to load the loop in your config.js correctly.

I don't think you can use localhost,

Because the NPM document says:
``
Server. Listen (port, [hostname], [backlog], [callback]) #

The Begin has connections on the specified port and the hostname. If the hostname is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY).

``
If you use NPM, you can try [0.0.0.0:port].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants