Mutation Testing for Web Applications CS 4501 / 6501 Software Testing

Slides:



Advertisements
Similar presentations
HTML Forms. collect information for passing to server- side processes built up from standard widgets –text-input, radio buttons, check boxes, option lists,
Advertisements

Hossain Shahriar Mohammad Zulkernine. One of the worst vulnerabilities in web applications It involves the generation of dynamic HTML contents with invalidated.
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Java Server Pages (JSP)
DT211/3 Internet Application Development JSP: Processing User input.
OCT1 Principles From Chapter One of “Distributed Systems Concepts and Design”
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
COMPUTER TERMS PART 1. COOKIE A cookie is a small amount of data generated by a website and saved by your web browser. Its purpose is to remember information.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
4.1 JavaScript Introduction
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
JavaScript and The Document Object Model MMIS 656 Web Design Technologies Acknowledgements: 1.Notes from David Shrader, NSU GSCIS 2.Some material adapted.
JavaScript & jQuery the missing manual Chapter 11
Introduction to Software Testing Chapter 5.2 Program-based Grammars Paul Ammann & Jeff Offutt
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
© 2011 Delmar, Cengage Learning Chapter 9 Collecting Data with Forms.
Server-side Scripting Powering the webs favourite services.
Week 10-11c Attacks and Malware III. Remote Control Facility distinguishes a bot from a worm distinguishes a bot from a worm worm propagates itself and.
Slide 12.1 Chapter 12 Implementation. Slide 12.2 Learning outcomes Produce a plan to minimize the risks involved with the launch phase of an e-business.
Introduction to JavaScript CS101 Introduction to Computing.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
Introduction to Software Testing Chapter 9.2 Program-based Grammars Paul Ammann & Jeff Offutt
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Mutation Testing Breaking the application to test it.
MUTACINIS TESTAVIMAS Benediktas Knispelis, IFM-2/2 Mutation testing.
Testing Web Applications (Adapted from Introduction to Software Testing Chapter 7.2 Engineering Criteria for Technologies) By Paul Ammann & Jeff Offutt.
Software Testing and Quality Assurance Syntax-Based Testing (2) 1.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Web Security (cont.) 1. Referral issues r HTTP referer (originally referrer) – HTTP header that designates calling resource  Page on which a link is.
Java Server Pages Can web pages be created specially for each user?
JavaScripts.
Tonga Institute of Higher Education IT 141: Information Systems
Using Mutation Analysis to Test Web Applications
Generating Automated Tests from Behavior Models
Web Development Web Servers.
Introduction to Software Testing Chapter 9.2 Program-based Grammars
Mutation Testing Moonzoo Kim School of Computing KAIST
Scripted Page Web App Development (Java Server Pages)
Section 17.1 Section 17.2 Add an audio file using HTML
Web Software Model CS 4640 Programming Languages for Web Applications
Mutation testing Julius Purvinis IFM-0/2.
PHP / MySQL Introduction
Syntax-based Testing CS 4501 / 6501 Software Testing
Introduction to Software Testing Chapter 5.1 Syntax-based Testing
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
Introduction to Web Applications
Introduction to Software Testing Chapter 9.2 Program-based Grammars
Paul Ammann & Jeff Offutt
Tonga Institute of Higher Education IT 141: Information Systems
Introduction to Software Testing Chapter 5.2 Program-based Grammars
Introduction to Servlets
JavaScript Form Validation
Lecture 2 - SQL Injection
Tonga Institute of Higher Education IT 141: Information Systems
Software Testing Syntax-based Testing.
CS3220 Web and Internet Programming Introduction to Java Servlets
Introduction to Software Testing Chapter 5.1 Syntax-based Testing
Mutation Testing Moonzoo Kim School of Computing KAIST
Back end Development CS Programming Languages for Web Applications
[Robert W. Sebesta, “Programming the World Wide Web
State Handling CS 4640 Programming Languages for Web Applications
Back end Development CS Programming Languages for Web Applications
State Handling CS 4640 Programming Languages for Web Applications
Mutation Testing Faults are introduced into the program by creating many versions of the program called mutants. Each mutant contains a single fault. Test.
Presentation transcript:

Mutation Testing for Web Applications CS 4501 / 6501 Software Testing

Mutation Testing Mutation operators review Mutation Testing Mutation operators Rules that specify how to modify the code (mutate) Well designed operators result in power tests Mutation operators do one of two tasks Mimic typical programmer mistakes Encourage common test heuristics We use mutation testing to Help testers design high quality tests Evaluate the quality of existing tests Mutation scores = # 𝑚𝑢𝑡𝑎𝑛𝑡𝑠 𝑘𝑖𝑙𝑙𝑒𝑑 # 𝑛𝑜𝑛−𝑒𝑞𝑢𝑖𝑣𝑎𝑙𝑒𝑛𝑡 𝑚𝑢𝑡𝑎𝑛𝑡𝑠 Subject programs Run tests on subject program Killing mutant Apply mutation operators Goals of mutation operators: Mimic typical programmer mistakes, thus trying to ensure that the tests can detect those mistakes Force the testers to create tests that have been found to effectively test software Uses of mutation testing Help generate tests Evaluate how good exiting tests (or criteria) are no Distinguishable result? yes Record killed mutants Generate tests mutants Run tests on mutants Must be valid strings (compilable) Mutants are not tests, but used to find tests

Killing mutants ≈ exposing faults review Given a mutant m  M for a ground string program P and a test t, t is said to kill m if and only if the output of t on P is different from the output of t on m. The quality of tests depends on mutation operators If the operators are designed well, the resulting testes will be very powerful Different operators must be defined for different programming languages and different goals Testers can keep adding tests until all mutants have been killed A mutant is killed if there is a test case for which the test results are different from the original program Killing mutants ≈ exposing faults

Mutation Coverage review Mutation Coverage (MC): For each m  M, TR contains exactly one requirement, to kill m. The RIPR model Reachability: the test causes the faulty (mutated) statement to be reached Infection: the test causes the faulty statement to result in an incorrect state Propagation: the incorrect state propagates to incorrect output Revealability: the tester must observe part of the incorrect output The RIPR model leads to two variants of mutation coverage: strong mutation and weak mutation

Designing Mutation Operators review Mutation Operators do one of two tasks: Mimic typical programmer mistakes Encourage common test heuristics Researchers design many operators, then experimentally Select the most useful operators Remove the redundant operators Effective Mutation Operators If tests that are created specifically to kill mutants created by a collection of mutation operators O = {o1, o2, …} also kill mutants created by all remaining mutation operators with very high probability, then O defines an effective set of mutation operators

Unit / Method Mutation Operators [http://cs.gmu.edu/~offutt/mujava/mutopsMethod.pdf]

OO Mutation Operators [http://cs.gmu.edu/~offutt/mujava/mutopsMethod.pdf]

Web App Software Failures Apr 2016: Clicking the browser back button while using the TurboTax web software caused a user to lose information Feb 2015: Anthem suffered data breach Jan 2014: Dropbox outage caused customers to lose information Aug 2013: Amazon hosting service failure caused business to lose information and revenue Sep 2012: Cyberattack on Bank of America, JPMorgan Chase, Citigroup, US Bank, Wells Fargo, and PNC resulted in denial of services Jun 2012: Clicking the browser back button after successfully logging off Amazon website exposed payment information of the recent order Mar 2012: BodyShop website turned a buy-one-get-one 50% off to a half price each item Feb 2011: Over 120,000 users were unable to access email accounts due to Google mail service outage Sep 2011: Failures at Target delayed and canceled many customers’ orders

Web Applications How many of you have developed web apps ? Web server Web component1 Web component2 Web componentn HTTP Request Have you noticed anything different from developing other software ? HttpServlet Request DB Web client HttpServlet Response Data HTTP response Web applications are constructed from diverse, distributed, and sometimes dynamically generated web components

Challenges in Testing Web Apps User’s ability to control web apps Identifying web resources with URLs Communication depending on HTTP requests Communication via data exchanges Novel control connections Server-side state management Client-side state management

Ch #1 – User’s Ability to Control Web Apps Potential faults: unintended transitions (such as breaking the flow of execution)

Ch #6 – Server-side State Management Potential faults: inappropriate scope setting inappropriate session object initialization omitting necessary session info application session request forward page request Client 1 request request forward page Client 2 request page

Ch #6 – Server-side State Management session scope Current GPA 4.0 (4*3)/3 4.0 (4*3 + (4*3 + 4*3)) / 9 3.6666667 (4*3 + (4*3 + 4*3) + (4*3 + 4*3 + 2*3)) / 18 Credit hours needed 30 more 27 more (30-3) 21 more (30-3-6) 12 more (30-3-6-9)

Ch #6 – Server-side State Management page scope Current GPA 4.0 (4*3)/3 4.0 (4*3 + 4*3) / 6 3.3333333 (4*3 + 4*3 + 2*3) / 9 Credit hours needed 30 more 27 more (30-3) 24 more (30-6) 21 more (30-9)

Ch #6 – Server-side State Management session scope Potential faults: inappropriate scope setting (objects/data are accessible when they should not be) page scope Traditional software do not have these features but we must consider them when testing web apps

Problem New features => Challenges => interaction faults. Improperly implementing and testing the communications among web components => interaction faults. Traditional software testing techniques => insufficient New features => new faults Little knowledge for how to test web apps Quality testing is very rare Traditional software testing techniques are insufficient for testing web apps due to the new features Current testing techniques are not effective at finding interaction faults.

Motivation Solution: mutation testing on web apps Provide more sophisticated testing than current practice Provide an evaluation criterion for other test selection strategies Filter redundant pre-existing tests Improve our ability to deliver quality web apps through stronger testing Solution: mutation testing on web apps

Mutation Testing Subject programs Run tests on subject program Apply Killing mutant Apply mutation operators no Distinguishable result? yes Record killed mutants Generate tests mutants Run tests on mutants Must be valid strings (compilable) Mutants are not tests, but used to find tests

From Challenges to Fault Model Potential Faults 1. Users’ ability to control web apps Unintended transitions caused by the user via a web browser or intentionally bypass the app validation 2. Identifying web resources with URLs Incorrect or inappropriate URLs 3. Comm. depending on HTTP requests Incorrect transfer mode (GET vs POST) 4. Comm. via data exchanges Mismatched parameters 5. Novel control connections Incorrect use between redirect and forward transitions 6. Server-side state management Incorrect scope setting Not initializing a session when it should be Omitting necessary session info 7. Client-side state management Omitting necessary info about hidden form fields Submitting incorrect info about hidden form fields Omitting necessary read-only info

Web Mutation Operators Challenges Potential Faults Web Mutation Operators 1. Users’ ability to control web apps Unintended transitions caused by the user via a web browser or intentionally bypass the app validation FOB Insert a dummy URL to the browser history before the current URL (or screen) 2. Identifying web resources with URLs Incorrect or inappropriate URLs WLUR Replace URL of href attr of an <A> tag WLUD Delete URL of href attr of an <A> tag WFUR Replace URL of href attr of an <form> tag WRUR Replace URL of sendRedirect method of an HttpServletResponse WCUR Replace URL of page attr of JSP forward action and JSP include action, and file attr of JSP include directive 3. Comm. depending on HTTP requests Incorrect transfer mode (GET vs POST) WFTR Replace a transfer mode with another transfer mode 4. Comm. via data exchanges Mismatched parameters WPVD Remove a parameter-value pair from JSP include action

Web Mutation Operators Challenges Potential Faults Web Mutation Operators 5. Novel control connections Incorrect use between redirect and forward transitions WCTR Replace a redirect transition with a forward transition and a forward transition with a redirect transition 6. Server-side state management Incorrect scope setting WSCR Replace scope of <jsp:useBean> with another setting (page, request, session, application) Not initializing a session object when it should be WSIR Change a session object initialization to the opposite behavior (i.e., whether to create an instance) Omitting necessary session info WSAD Delete setAttribute method of a session object 7. Client-side state management Omitting necessary info about hidden form fields WHID Delete a hidden form field Submitting incorrect info about hidden form fields WHIR Replace value of a hidden form field with another value in the same application domain Omitting necessary read-only info WOID Delete a read-only input control

Mutation Operator for Faults due to Operational Transitions FOB – FailOnBack <html> … <body> <body onload=“manipulatehistory()”> <script src=“failOnBack.js”></script> </html> failOnBack.js function manipulatehistory() { var currentpage = window.document.toString(); var currenturl = window.location.href; var pageData = window.document.toString(); // add a dummy url right before the current url history.replaceState( pageData, “dummyurl”, “failonback.html” ); history.pushState( currentpage, “currenturl”, currenturl); } // update the page content window.addEventListener( ‘popstate’, function(event) { window.location.reload(); }); URL_C URL_F URL_2 URL_1 URL_P URL_P URL_2 URL_1 URL_C browser history

Example Test for FOB Mutant public void test_FOB_1() { driver.get("http://localhost:8080/experiment/calculategpa.jsp"); assertEquals("Grade Calculator", driver.getTitle()); // simulate a form submission WebElement element = driver.findElement(By.name("courseName1")); element.sendKeys("swe1"); driver.findElement(By.xpath("//input[@type='radio' and @name='courseGrade1' and @value='B+']")).click(); WebElement btn = driver.findElement(By.xpath("//button[@name='submitCourses']")); btn.click(); // check if system works properly when clicking the browser back button driver.navigate().back(); assertEquals(true, driver.getPageSource().contains( "Calculates the current GPA and the minimum GPA needed in the remaining classes")); }

Mutation Operators for Faults due to Control Connection WCTR – Control transition replacement Public class logout extends HttpServlet { ... public void doGet( ... ) response.sendRedirect(url1); getServletContext().getRequestDispatcher(url1) .forward(request, response); }

Mutation Operators for Faults due to Server-Side State Management WSCR – Scope replacement <html> … <jsp:useBean id = id1 scope = “page” class = class1 /> <jsp:useBean id = id1 scope = “session” class = class1 /> </html> WSIR – Session initialization replacement Public class logout extends HttpServlet { public void doGet( ... ) session = request.getSession(true); session = request.getSession(false); ... } } WSAD – Session setAttribute deletion session.setAttribute(attr1 , value1 ); // session.setAttribute(attr1 , value1 );

Example Test for WSCR Mutant public void test_WSCR_1() { driver.get("http://localhost:8080/experiment/calculategpa.jsp"); assertEquals("Grade Calculator", driver.getTitle()); // simulate a form submission WebElement element = driver.findElement(By.name("courseName1")); element.sendKeys("swe1"); driver.findElement(By.xpath("//input[@type='radio' and @name='courseGrade1' and @value='A']")).click(); WebElement btn = driver.findElement(By.xpath("//button[@name='submitCourses']")); btn.click(); assertEquals(true, driver.getPageSource().contains("Your current GPA is: 4.0")); // simulate another form submission WebElement linkelement = driver.findElement(By.linkText("Add another course")); linkelement.click(); element = driver.findElement(By.name("courseName2")); element.sendKeys("swe2"); driver.findElement(By.xpath("//input[@type='radio' and @name='courseGrade2' and @value='B']")).click(); btn = driver.findElement(By.xpath("//button[@name='submitCourses']")); assertEquals(true, driver.getPageSource().contains("You need 24 more hours to graduate.")); }

Mutation Operators for JS Web App [“Efficient JavaScript Mutation Testing,” S. Mirshokraie, A. Mesbah, and K. Pattabiraman]

Mutation Operators for JS Web App [“Efficient JavaScript Mutation Testing,” S. Mirshokraie, A. Mesbah, and K. Pattabiraman]

Summary Mutation is widely considered the strongest test criterion Some Java mutation operators can be applied to web apps but operators dealing with web-specific features are needed Mutation operators have been defined for Java web app and JavaScript Current mutation testing tools for web apps apply to source code. Program schema may be used to speed up the tool Equivalent mutants are hand-analysis … we need to develop more cost-effective approach Correlation between web mutation operators and fault severity can be useful for software maintenance and repair