2015-06-08 18:29:37 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2010-2015 SAP SE.
|
|
|
|
*
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-08-21 21:00:54 +00:00
|
|
|
package eu.aniketos.dasca.dataflow.testdata;
|
2015-06-08 18:29:37 +00:00
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.Statement;
|
|
|
|
|
2016-08-21 21:00:54 +00:00
|
|
|
import eu.aniketos.dasca.dataflow.testdata.dummy.IO;
|
2015-06-08 18:29:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Test Case 12:
|
|
|
|
//reachability from bad sink to bad source via multiple if-statements and boolean expressions combined with arithmetics
|
|
|
|
public class Test12 {
|
2015-06-08 19:43:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* bad for i==3 and !x
|
|
|
|
*/
|
2015-06-08 18:29:37 +00:00
|
|
|
public void bad(boolean x, int i) {
|
|
|
|
String userName = null;
|
|
|
|
if(x | i > 3) {
|
2015-06-08 19:43:23 +00:00
|
|
|
userName = IO.readLineGood();
|
|
|
|
} else {
|
|
|
|
userName = IO.readLine();
|
2015-06-08 18:29:37 +00:00
|
|
|
}
|
2015-06-08 19:43:23 +00:00
|
|
|
|
|
|
|
if( i < 3 ) {
|
2015-06-08 18:29:37 +00:00
|
|
|
userName = IO.readLineGood();
|
|
|
|
}
|
|
|
|
Connection conn = IO.getDBConnection();
|
|
|
|
try {
|
|
|
|
Statement stmt = conn.createStatement();
|
|
|
|
stmt.execute("SELECT * FROM user WHERE name='" + userName + "';");
|
|
|
|
} catch(SQLException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void good01(boolean x, int i) {
|
|
|
|
String userName = null;
|
|
|
|
if(x | i > 3) {
|
2015-06-08 19:43:23 +00:00
|
|
|
userName = IO.readLineGood();
|
|
|
|
} else {
|
|
|
|
userName = IO.readLine();
|
2015-06-08 18:29:37 +00:00
|
|
|
}
|
2015-06-08 19:43:23 +00:00
|
|
|
|
|
|
|
if(!x & i <= 3 ) {
|
2015-06-08 18:29:37 +00:00
|
|
|
userName = IO.readLineGood();
|
|
|
|
}
|
|
|
|
Connection conn = IO.getDBConnection();
|
|
|
|
try {
|
|
|
|
Statement stmt = conn.createStatement();
|
|
|
|
stmt.execute("SELECT * FROM user WHERE name='" + userName + "';");
|
|
|
|
} catch(SQLException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2015-06-08 19:43:23 +00:00
|
|
|
|
2015-06-08 18:29:37 +00:00
|
|
|
public static void main(String[] args) {
|
2015-06-08 19:43:23 +00:00
|
|
|
Test12 test = new Test12();
|
|
|
|
test.good01(true, 5);
|
|
|
|
test.bad(true, 5);
|
|
|
|
}
|
2015-06-08 18:29:37 +00:00
|
|
|
}
|