// Path: src/test/java/ysoserial/test/CustomTest.java
// public interface CustomTest extends CustomPayloadArgs {
// 
//     void run (Callable<Object> payload) throws Exception;
// }
// 
// Path: src/test/java/ysoserial/test/util/OS.java
// public enum OS {
//     WINDOWS,
//     LINUX,
//     OSX,
//     OTHER;
// 
//     private static final OS os = determineOs();
// 
//     public static OS get() {
//         return os;
//     }
// 
//     private static OS determineOs() {
//         String osName = System.getProperty("os.name", "other").toLowerCase();
//         if (osName.contains("windows")) {
//             return WINDOWS;
//         } else if (osName.contains("mac os x")) {
//             return OSX;
//         } else if (osName.contains("linux")) {
//             return LINUX;
//         } else {
//             return OTHER;
//         }
//     }
// 
//     public static String getTmpDir() {
//         return System.getProperty("java.io.tmpdir");
//     }
// }


import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.Callable;
import org.junit.Assert;
import com.google.common.io.Files;
import ysoserial.test.CustomTest;
import ysoserial.test.util.OS;
package ysoserial.test.payloads;





/**
 * @author mbechler
 *
 */
public class FileUploadTest implements CustomTest {

    /**
     *
     */
    private static final byte[] FDATA = new byte[] {(byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF };
    private File source;
    private File repo;


    /**
     *
     */
    public FileUploadTest () {
        try {
            source = File.createTempFile("fut", "-source");
            repo = Files.createTempDir();
        }
        catch ( IOException e ) {
            e.printStackTrace();
        }
    }


    public synchronized void run ( Callable<Object> payload ) throws Exception {
        try {
            Files.write(FDATA, this.source);
            Assert.assertTrue(this.source.exists());
            payload.call();

            File found = null;
            for (int i = 0; i < 50 && found == null; i++) { // try for 5s before failing
                for (File f : this.repo.listFiles()) {
                    found = f;
                    break;
                }
                Thread.sleep(100);
            }
            Assert.assertNotNull("File not copied", found);
// Path: src/test/java/ysoserial/test/CustomTest.java
// public interface CustomTest extends CustomPayloadArgs {
// 
//     void run (Callable<Object> payload) throws Exception;
// }
// 
// Path: src/test/java/ysoserial/test/util/OS.java
// public enum OS {
//     WINDOWS,
//     LINUX,
//     OSX,
//     OTHER;
// 
//     private static final OS os = determineOs();
// 
//     public static OS get() {
//         return os;
//     }
// 
//     private static OS determineOs() {
//         String osName = System.getProperty("os.name", "other").toLowerCase();
//         if (osName.contains("windows")) {
//             return WINDOWS;
//         } else if (osName.contains("mac os x")) {
//             return OSX;
//         } else if (osName.contains("linux")) {
//             return LINUX;
//         } else {
//             return OTHER;
//         }
//     }
// 
//     public static String getTmpDir() {
//         return System.getProperty("java.io.tmpdir");
//     }
// }


// Path: src/test/java/ysoserial/test/payloads/FileUploadTest.java
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.Callable;
import org.junit.Assert;
import com.google.common.io.Files;
import ysoserial.test.CustomTest;
import ysoserial.test.util.OS;

package ysoserial.test.payloads;





/**
 * @author mbechler
 *
 */
public class FileUploadTest implements CustomTest {

    /**
     *
     */
    private static final byte[] FDATA = new byte[] {(byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF };
    private File source;
    private File repo;


    /**
     *
     */
    public FileUploadTest () {
        try {
            source = File.createTempFile("fut", "-source");
            repo = Files.createTempDir();
        }
        catch ( IOException e ) {
            e.printStackTrace();
        }
    }


    public synchronized void run ( Callable<Object> payload ) throws Exception {
        try {
            Files.write(FDATA, this.source);
            Assert.assertTrue(this.source.exists());
            payload.call();

            File found = null;
            for (int i = 0; i < 50 && found == null; i++) { // try for 5s before failing
                for (File f : this.repo.listFiles()) {
                    found = f;
                    break;
                }
                Thread.sleep(100);
            }
            Assert.assertNotNull("File not copied", found);
            if (OS.get() != OS.WINDOWS) {