appium: iOS Driver Build is Broken: SQLITE_CANTOPEN

I’ve tracked the problem down to there not being a Librarys/Keychains/TrustStore.sqlite3 directory in the sim’s data dir, on Travis. Not sure why this would be. But the certificate trust store module then dies with SQLITE_CANTOPEN error that is uncatchable, for some reason.

The temporary solution is probably to quarantine the test on Travis. See https://github.com/appium/appium-ios-driver/pull/201

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (14 by maintainers)

Most upvoted comments

The most naive, brute force way to fix this is to create the paths/file/table. This is obviously fragile and can break without notice. Is there some way to trigger the simulator to create these files without have to manually recreate a SQLite database/table/schema?

Otherwise, here’s a patch for getting the file created. It goes in appium-ios-simulator. I’m not inclined to submit a PR for this since it’s sooo hacky:

diff --git a/lib/certificate.js b/lib/certificate.js
index 11cf4e7..6b10150 100644
--- a/lib/certificate.js
+++ b/lib/certificate.js
@@ -1,6 +1,8 @@
+import log from './logger';
 import crypto from 'crypto';
 import B from 'bluebird';
 import path from 'path';
+import fs from 'fs';

 const sqlite3 = B.promisifyAll(require('sqlite3'));
 const openssl = B.promisify(require('openssl-wrapper').exec);
@@ -110,8 +112,22 @@ class Certificate {
  */
 class TrustStore {
   constructor (sharedResourceDir) {
-    this.sqliteDBPath = path.resolve(sharedResourceDir, 'Library/Keychains/TrustStore.sqlite3');
+    let sqlDBFolder = path.resolve(sharedResourceDir, 'Library/Keychains');
+    let folderExists = fs.existsSync(sqlDBFolder);
+    if (!folderExists) {
+      log.warn('SQLite DB folder did not exist. Creating');
+      fs.mkdirSync(sqlDBFolder);
+    }
+
+    this.sqliteDBPath = path.resolve(sqlDBFolder, 'TrustStore.sqlite3');
+    let dbFileExists = fs.existsSync(this.sqliteDBPath);
     this.db = new sqlite3.Database(this.sqliteDBPath);
+
+    // We'll have to create the tables
+    if (!dbFileExists) {
+      log.warn('Recreating SQLite DB...');
+      this.db.exec("CREATE TABLE tsettings(sha1 BLOB NOT NULL DEFAULT '',subj BLOB NOT NULL DEFAULT '',tset BLOB,data BLOB,PRIMARY KEY(sha1)); CREATE INDEX isubj ON tsettings(subj);");
+    }
   }

   /**

The schema was lifted from opening and inspecting the TrustStore DB after drag/dropping a self-signed cert onto the simulator and installing it.