// Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations under // the License. couchTests.cookie_auth = function(debug) { // This tests cookie-based authentication. var db_name = get_random_db_name(); var db = new CouchDB(db_name, {"X-Couch-Full-Commit":"false"}); db.createDb(); // used later, needs to be global here var users_db_name = '_users'; var usersDb = new CouchDB(users_db_name, {"X-Couch-Full-Commit":"false"}); try { usersDb.createDb(); } catch (e) { /* ignore if exists*/ } if (debug) debugger; var password = "3.141592653589"; var loginUser = function(username) { var pws = { jan: "apple", "Jason Davies": password, jchris: "funnybone" }; var username1 = username.replace(/[0-9]$/, ""); var password = pws[username]; //console.log("Logging in '" + username1 + "' with password '" + password + "'"); T(CouchDB.login(username1, pws[username]).ok); }; var open_as = function(db, docId, username) { loginUser(username); try { return db.open(docId, {"anti-cache": Math.round(Math.random() * 100000)}); } finally { CouchDB.logout(); } }; var save_as = function(db, doc, username) { loginUser(username); try { return db.save(doc); } catch (ex) { return ex; } finally { CouchDB.logout(); } }; // Simple secret key generator function generateSecret(length) { var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var secret = ''; for (var i=0; i