Set correct permissions for moved certificates, added missing test changes.
This commit is contained in:
parent
f7952aa9ce
commit
387202d92d
5 changed files with 47 additions and 12 deletions
|
@ -4,8 +4,8 @@ import android.test.AndroidTestCase;
|
|||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nutomic.zertman.Certificate;
|
||||
import com.nutomic.zertman.CertificateAdapter;
|
||||
import com.nutomic.zertman.*;
|
||||
import com.nutomic.zertman.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -19,7 +19,9 @@ public class CertificateAdapterTest extends AndroidTestCase {
|
|||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
mCertificateAdapter = new CertificateAdapter(getContext());
|
||||
CertificateManager cm = new CertificateManager();
|
||||
MovedCertificatesStorage mv = new MovedCertificatesStorage(getContext());
|
||||
mCertificateAdapter = new CertificateAdapter(getContext(), cm, mv);
|
||||
mTestCertificates.add(new Certificate("first", false));
|
||||
mTestCertificates.add(new Certificate("second", true));
|
||||
mCertificateAdapter.addAll(mTestCertificates);
|
||||
|
@ -29,7 +31,7 @@ public class CertificateAdapterTest extends AndroidTestCase {
|
|||
public void testAdapter() {
|
||||
for (int i = 0; i < mTestCertificates.size(); i++) {
|
||||
TextView tv1 = (TextView) mCertificateAdapter.getView(i, null, null)
|
||||
.findViewById(android.R.id.text1);
|
||||
.findViewById(R.id.title);
|
||||
assertTrue(tv1.getText().equals(mTestCertificates.get(i).getFile().getName()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,15 +3,20 @@ package com.nutomic.zertman.test;
|
|||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.util.Log;
|
||||
|
||||
import com.nutomic.zertman.Certificate;
|
||||
import com.nutomic.zertman.CertificateManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.List;
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell;
|
||||
|
@ -51,12 +56,46 @@ public class CertificateManagerTest extends AndroidTestCase {
|
|||
assertNotNull(newCertificate);
|
||||
assertEquals(newCertificate.getFile().getName(), cert.getFile().getName());
|
||||
assertNotSame(newCertificate.getFile(), cert.getFile());
|
||||
assertPermissions(newCertificate.getFile(), "-rw-r--r--");
|
||||
assertFalse(mCertificateManager.getCertificates(false).contains(cert));
|
||||
assertTrue(mCertificateManager.getCertificates(true).contains(newCertificate));
|
||||
assertTrue(mCertificateManager.deleteCertificate(newCertificate));
|
||||
assertReadOnly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that file has the given permissions.
|
||||
*/
|
||||
private void assertPermissions(File file, String expectedPermissions) {
|
||||
Process process;
|
||||
DataOutputStream dos = null;
|
||||
InputStreamReader isr = null;
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
process = Runtime.getRuntime().exec("sh");
|
||||
dos = new DataOutputStream(process.getOutputStream());
|
||||
isr = new InputStreamReader(process.getInputStream());
|
||||
dos.writeBytes("ls -l " + file.getAbsolutePath() + "\n");
|
||||
dos.writeBytes("exit\n");
|
||||
br = new BufferedReader(isr);
|
||||
assertTrue(br.readLine().startsWith(expectedPermissions));
|
||||
dos.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
fail();
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
dos.close();
|
||||
br.close();
|
||||
isr.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testSystemCertificates() {
|
||||
Certificate cert = copyCertificate(true);
|
||||
|
|
|
@ -31,11 +31,6 @@ public class MovedCertificatesStorageTest extends AndroidTestCase {
|
|||
mMovedCertificatesStorage.close();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testInvalidInsert() {
|
||||
assertFalse(mMovedCertificatesStorage.insert(new Certificate("user", false)));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testInvalidDelete() {
|
||||
assertFalse(mMovedCertificatesStorage.delete(new Certificate("cert", true)));
|
||||
|
|
|
@ -53,6 +53,7 @@ public class CertificateManager {
|
|||
// NOTE: Using mv gives error: "failed on *file* - Cross-device link".
|
||||
run("cp " + USER_CERTIFICATES_DIR + "/" + certificate.getFile().getName() +
|
||||
" " + SYSTEM_CERTIFICATES_DIR + "/" + certificate.getFile().getName());
|
||||
run("chmod 644 " + SYSTEM_CERTIFICATES_DIR + "/" + certificate.getFile().getName());
|
||||
remountSystem(Mode.ReadOnly);
|
||||
deleteCertificate(certificate);
|
||||
return new Certificate(certificate.getFile().getName(), true);
|
||||
|
|
|
@ -32,8 +32,6 @@ public class MainActivity extends ListActivity {
|
|||
new CertificateAdapter(this, mCertificateManager, mMovedCertificatesStorage);
|
||||
|
||||
mCertificateAdapter.addAll(mCertificateManager.getCertificates(false));
|
||||
// FIXME: nothing listed
|
||||
// -> db table is empty
|
||||
mCertificateAdapter.addAll(mMovedCertificatesStorage.list());
|
||||
mListView.setAdapter(mCertificateAdapter);
|
||||
}
|
||||
|
|
Reference in a new issue