coookies 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/CHANGES.md +16 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +28 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/bin/cookie_extractor +47 -0
- data/cookie_extractor.gemspec +22 -0
- data/lib/cookie_extractor.rb +11 -0
- data/lib/cookie_extractor/browser_detector.rb +78 -0
- data/lib/cookie_extractor/chrome_cookie_extractor.rb +29 -0
- data/lib/cookie_extractor/common.rb +19 -0
- data/lib/cookie_extractor/firefox_cookie_extractor.rb +29 -0
- data/lib/cookie_extractor/version.rb +3 -0
- data/spec/browser_detector_spec.rb +80 -0
- data/spec/chrome_cookie_extractor_spec.rb +126 -0
- data/spec/cookie_extractor_spec.rb +6 -0
- data/spec/firefox_cookie_extractor_spec.rb +136 -0
- data/spec/spec_helper.rb +2 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ed65d3647b297736118c3369a1506f7bb48bfdf2
|
4
|
+
data.tar.gz: 67a10192ed5f72cd0cc19e18a70eeed3265238f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ead52c05c49e812b3a522d87c9379b2ffb1682ba36e6320163fdf975ae1115d48b76d53841ca6c4562c404838463108f397e3452288340b4391614546cfa29ec
|
7
|
+
data.tar.gz: c8ee28c5e8d137ee996c7c60e3539f52f2caaeac860b34ce5b53e570997643066e38b8d9d8414ee8934cdeebc22f72c0f6bdf236f62386ccdf100456e3caca58
|
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use default@cookie-extractor
|
data/CHANGES.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
CHANGES: cookie_extractor
|
2
|
+
-------------------------
|
3
|
+
|
4
|
+
### v0.2.0 2013-07-02
|
5
|
+
|
6
|
+
- Browser guessing code contributed by Ben Eills (github.com/beneills):
|
7
|
+
- Added --guess flag to automatically choose most recently used cookie file
|
8
|
+
- Added --browser flag to specify browser by name
|
9
|
+
|
10
|
+
### v0.1.0 2012-02-23
|
11
|
+
|
12
|
+
- Updated to include Chrome/Chromium support.
|
13
|
+
|
14
|
+
### v0.0.1 2012-02-20
|
15
|
+
|
16
|
+
- Initial version. Supports extracting Firefox cookies.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cookie_extractor (0.0.1)
|
5
|
+
sqlite3-ruby
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
rspec (2.8.0)
|
12
|
+
rspec-core (~> 2.8.0)
|
13
|
+
rspec-expectations (~> 2.8.0)
|
14
|
+
rspec-mocks (~> 2.8.0)
|
15
|
+
rspec-core (2.8.0)
|
16
|
+
rspec-expectations (2.8.0)
|
17
|
+
diff-lcs (~> 1.1.2)
|
18
|
+
rspec-mocks (2.8.0)
|
19
|
+
sqlite3 (1.3.5)
|
20
|
+
sqlite3-ruby (1.3.3)
|
21
|
+
sqlite3 (>= 1.3.3)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
cookie_extractor!
|
28
|
+
rspec
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
cookie_extractor
|
2
|
+
----------------
|
3
|
+
|
4
|
+
Extract cookies from Firefox, Chrome or Chromium sqlite cookie stores into a wget-compatible cookies.txt file.
|
5
|
+
|
6
|
+
### Install ###
|
7
|
+
|
8
|
+
gem install cookie_extractor
|
9
|
+
|
10
|
+
### Usage ###
|
11
|
+
|
12
|
+
cookie_extractor /path/to/firefox/cookies.sqlite > cookies.txt
|
13
|
+
|
14
|
+
cookie_extractor --guess # Guess which browser to use and open corresponding file
|
15
|
+
|
16
|
+
cookie_extractor --browser chrome|chromium|firefox # Open corresponding DB
|
17
|
+
|
18
|
+
|
19
|
+
Typical locations for the cookies file on Linux are:
|
20
|
+
|
21
|
+
* Firefox: *~/.mozilla/firefox/(profile directory)/cookies.sqlite*
|
22
|
+
* Chrome: *~/.config/google-chrome/Default/Cookies*
|
23
|
+
* Chromium: *~/.config/chromium/Default/Cookies*
|
24
|
+
|
25
|
+
### License ###
|
26
|
+
|
27
|
+
Copyright (c) 2012 Jeff Dallien
|
28
|
+
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
30
|
+
|
31
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
32
|
+
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "cookie_extractor"))
|
4
|
+
|
5
|
+
|
6
|
+
def usage msg=nil
|
7
|
+
puts msg if msg
|
8
|
+
puts "Usage: cookie_extractor /path/to/cookies.sqlite Open a DB file"
|
9
|
+
puts " cookie_extractor --guess Guess which browser to use and open corresponding file"
|
10
|
+
puts " cookie_extractor --browser chrome|chromium|firefox Open DB corresponding to a particular browser"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
begin
|
16
|
+
extractor =
|
17
|
+
case ARGV.first
|
18
|
+
when '--guess', '-g'
|
19
|
+
begin
|
20
|
+
CookieExtractor::BrowserDetector.guess()
|
21
|
+
rescue CookieExtractor::NoCookieFileFoundException
|
22
|
+
abort "Error: we couldn't find any supported broswer's cookies"
|
23
|
+
end
|
24
|
+
when '--browser', '-b'
|
25
|
+
browser = ARGV[1]
|
26
|
+
usage "Error: Please supply a browser name" unless browser
|
27
|
+
begin
|
28
|
+
CookieExtractor::BrowserDetector.browser_extractor(browser)
|
29
|
+
rescue CookieExtractor::InvalidBrowserNameException
|
30
|
+
abort "Error: '#{browser}' is not a valid browser name"
|
31
|
+
rescue CookieExtractor::NoCookieFileFoundException
|
32
|
+
abort "Error: Could not locate cookie file for browser #{browser}"
|
33
|
+
end
|
34
|
+
when nil
|
35
|
+
usage
|
36
|
+
else
|
37
|
+
filename = ARGV.first
|
38
|
+
abort "Error: #{filename} does not exist" unless File.exists?(filename)
|
39
|
+
CookieExtractor::BrowserDetector.new_extractor(filename)
|
40
|
+
end
|
41
|
+
puts extractor.extract.join("\n")
|
42
|
+
rescue SQLite3::NotADatabaseException,
|
43
|
+
CookieExtractor::BrowserNotDetectedException
|
44
|
+
abort "Error: File '#{filename}' is not a Firefox or Chrome cookie database"
|
45
|
+
end
|
46
|
+
|
47
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cookie_extractor/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "coookies"
|
7
|
+
s.version = CookieExtractor::VERSION
|
8
|
+
s.authors = ["Matias Fernandez"]
|
9
|
+
s.email = ["matiasfmolinari@gmail.com"]
|
10
|
+
s.summary = %q{Create cookies.txt from Firefox or Chrome/Chromium cookies}
|
11
|
+
s.description = %q{Extract cookies from Firefox, Chrome or Chromium sqlite databases into a wget-compatible cookies.txt file.}
|
12
|
+
|
13
|
+
s.rubyforge_project = "cookie_extractor"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency "rspec", "~> 2.8"
|
21
|
+
s.add_runtime_dependency "sqlite3", "~> 1.3"
|
22
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require "cookie_extractor/version"
|
5
|
+
require "cookie_extractor/common"
|
6
|
+
require "cookie_extractor/firefox_cookie_extractor"
|
7
|
+
require "cookie_extractor/chrome_cookie_extractor"
|
8
|
+
require "cookie_extractor/browser_detector"
|
9
|
+
|
10
|
+
module CookieExtractor
|
11
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module CookieExtractor
|
2
|
+
class BrowserNotDetectedException < Exception; end
|
3
|
+
class InvalidBrowserNameException < Exception; end
|
4
|
+
class NoCookieFileFoundException < Exception; end
|
5
|
+
|
6
|
+
class BrowserDetector
|
7
|
+
COOKIE_LOCATIONS = {
|
8
|
+
"chrome" => "~/.config/google-chrome/Default/Cookies",
|
9
|
+
"chromium" => "~/.config/chromium/Default/Cookies",
|
10
|
+
"firefox" => "~/.mozilla/firefox/*.default/cookies.sqlite"
|
11
|
+
}
|
12
|
+
|
13
|
+
# Returns the extractor of the most recently used browser's cookies
|
14
|
+
# or raise NoCookieFileFoundException if there are no cookies
|
15
|
+
def self.guess
|
16
|
+
most_recently_used_detected_browsers.each { |browser, path|
|
17
|
+
begin
|
18
|
+
extractor = self.browser_extractor(browser)
|
19
|
+
rescue BrowserNotDetectedException, NoCookieFileFoundException
|
20
|
+
# better try the next one...
|
21
|
+
else
|
22
|
+
return extractor
|
23
|
+
end
|
24
|
+
}
|
25
|
+
# If we make it here, we've failed...
|
26
|
+
raise NoCookieFileFoundException, "Couldn't find any browser's cookies"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Open a browser's cookie file using intelligent guesswork
|
30
|
+
def self.browser_extractor(browser)
|
31
|
+
raise InvalidBrowserNameException, "Browser must be one of: #{self.supported_browsers.join(', ')}" unless self.supported_browsers.include?(browser)
|
32
|
+
paths = Dir.glob(File.expand_path(COOKIE_LOCATIONS[browser]))
|
33
|
+
if paths.length < 1 or not File.exists?(paths.first)
|
34
|
+
raise NoCookieFileFoundException, "File #{paths.first} does not exist!"
|
35
|
+
end
|
36
|
+
self.new_extractor(paths.first)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.new_extractor(db_filename)
|
40
|
+
browser = detect_browser(db_filename)
|
41
|
+
if browser
|
42
|
+
CookieExtractor.const_get("#{browser}CookieExtractor").new(db_filename)
|
43
|
+
else
|
44
|
+
raise BrowserNotDetectedException, "Could not detect browser type."
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.supported_browsers
|
49
|
+
COOKIE_LOCATIONS.keys
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.detect_browser(db_filename)
|
53
|
+
db = SQLite3::Database.new(db_filename)
|
54
|
+
browser =
|
55
|
+
if has_table?(db, 'moz_cookies')
|
56
|
+
'Firefox'
|
57
|
+
elsif has_table?(db, 'cookies')
|
58
|
+
'Chrome'
|
59
|
+
end
|
60
|
+
db.close
|
61
|
+
browser
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.has_table?(db, table_name)
|
65
|
+
db.table_info(table_name).size > 0
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.most_recently_used_detected_browsers
|
69
|
+
COOKIE_LOCATIONS.select { |browser, path|
|
70
|
+
Dir.glob(File.expand_path(path)).any?
|
71
|
+
}.sort_by { |browser, path|
|
72
|
+
File.mtime(Dir.glob(File.expand_path(path)).first)
|
73
|
+
}.reverse
|
74
|
+
end
|
75
|
+
|
76
|
+
private_class_method :most_recently_used_detected_browsers
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
|
3
|
+
module CookieExtractor
|
4
|
+
class ChromeCookieExtractor
|
5
|
+
include Common
|
6
|
+
|
7
|
+
def initialize(cookie_file)
|
8
|
+
@cookie_file = cookie_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def extract
|
12
|
+
db = SQLite3::Database.new @cookie_file
|
13
|
+
db.results_as_hash = true
|
14
|
+
result = []
|
15
|
+
db.execute("SELECT * FROM cookies") do |row|
|
16
|
+
result << [ row['host_key'],
|
17
|
+
true_false_word(is_domain_wide(row['host_key'])),
|
18
|
+
row['path'],
|
19
|
+
true_false_word(row['secure']),
|
20
|
+
row['expires_utc'],
|
21
|
+
row['name'],
|
22
|
+
row['value']
|
23
|
+
].join("\t")
|
24
|
+
end
|
25
|
+
db.close
|
26
|
+
result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CookieExtractor
|
2
|
+
module Common
|
3
|
+
private
|
4
|
+
|
5
|
+
def is_domain_wide(hostname)
|
6
|
+
hostname[0..0] == "."
|
7
|
+
end
|
8
|
+
|
9
|
+
def true_false_word(value)
|
10
|
+
if value == "1" || value == 1 || value == true
|
11
|
+
"TRUE"
|
12
|
+
elsif value == "0" || value == 0 || value == false
|
13
|
+
"FALSE"
|
14
|
+
else
|
15
|
+
raise "Invalid value passed to true_false_word: #{value.inspect}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
|
3
|
+
module CookieExtractor
|
4
|
+
class FirefoxCookieExtractor
|
5
|
+
include Common
|
6
|
+
|
7
|
+
def initialize(cookie_file)
|
8
|
+
@cookie_file = cookie_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def extract
|
12
|
+
db = SQLite3::Database.new @cookie_file
|
13
|
+
db.results_as_hash = true
|
14
|
+
result = []
|
15
|
+
db.execute("SELECT * FROM moz_cookies") do |row|
|
16
|
+
result << [ row['host'],
|
17
|
+
true_false_word(is_domain_wide(row['host'])),
|
18
|
+
row['path'],
|
19
|
+
true_false_word(row['isSecure']),
|
20
|
+
row['expiry'],
|
21
|
+
row['name'],
|
22
|
+
row['value']
|
23
|
+
].join("\t")
|
24
|
+
end
|
25
|
+
db.close
|
26
|
+
result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe CookieExtractor::BrowserDetector, "determining the correct extractor to use" do
|
4
|
+
before :each do
|
5
|
+
@fake_cookie_db = double("cookie database", :close => true)
|
6
|
+
SQLite3::Database.should_receive(:new).
|
7
|
+
with('filename').
|
8
|
+
and_return(@fake_cookie_db)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "given a sqlite database with a 'moz_cookies' table" do
|
12
|
+
before :each do
|
13
|
+
@fake_cookie_db.should_receive(:table_info).
|
14
|
+
with("moz_cookies").
|
15
|
+
and_return(
|
16
|
+
{ 'name' => 'some_field',
|
17
|
+
'type' => "some_type" })
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return a firefox extractor instance" do
|
21
|
+
extractor = CookieExtractor::BrowserDetector.new_extractor('filename')
|
22
|
+
extractor.instance_of?(CookieExtractor::FirefoxCookieExtractor).should be_true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "given a sqlite database with a 'cookies' table" do
|
27
|
+
before :each do
|
28
|
+
@fake_cookie_db.should_receive(:table_info).
|
29
|
+
with("moz_cookies").
|
30
|
+
and_return([])
|
31
|
+
@fake_cookie_db.should_receive(:table_info).
|
32
|
+
with("cookies").
|
33
|
+
and_return(
|
34
|
+
[{ 'name' => 'some_field',
|
35
|
+
'type' => "some_type" }])
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return a chrome extractor instance" do
|
39
|
+
extractor = CookieExtractor::BrowserDetector.new_extractor('filename')
|
40
|
+
extractor.instance_of?(CookieExtractor::ChromeCookieExtractor).should be_true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe CookieExtractor::BrowserDetector, "guessing the location of the cookie file" do
|
46
|
+
describe "when no cookie files are found in the standard locations" do
|
47
|
+
before :each do
|
48
|
+
Dir.stub!(:glob).and_return([])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise NoCookieFileFoundException" do
|
52
|
+
lambda { CookieExtractor::BrowserDetector.guess }.
|
53
|
+
should raise_error(CookieExtractor::NoCookieFileFoundException)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "when multiple cookie files are found in the standard locations" do
|
58
|
+
before :each do
|
59
|
+
cookie_locations = CookieExtractor::BrowserDetector::COOKIE_LOCATIONS
|
60
|
+
Dir.stub!(:glob).and_return([cookie_locations['chrome']],
|
61
|
+
[],
|
62
|
+
[cookie_locations['firefox']])
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "and chrome was the most recently used" do
|
66
|
+
before :each do
|
67
|
+
File.should_receive(:mtime).twice.and_return(
|
68
|
+
Time.parse("July 2 2013 00:00:00"),
|
69
|
+
Time.parse("July 1 2013 00:00:00"))
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should build a ChromeCookieExtractor" do
|
73
|
+
CookieExtractor::BrowserDetector.
|
74
|
+
should_receive(:browser_extractor).
|
75
|
+
once.with("chrome")
|
76
|
+
CookieExtractor::BrowserDetector.guess
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe CookieExtractor::ChromeCookieExtractor do
|
4
|
+
before :each do
|
5
|
+
@fake_cookie_db = double("cookie database",
|
6
|
+
:results_as_hash= => true,
|
7
|
+
:close => true)
|
8
|
+
SQLite3::Database.should_receive(:new).
|
9
|
+
with('filename').
|
10
|
+
and_return(@fake_cookie_db)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "opening and closing a sqlite db" do
|
14
|
+
before :each do
|
15
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
16
|
+
{ 'host_key' => '.dallien.net',
|
17
|
+
'path' => '/',
|
18
|
+
'secure' => '0',
|
19
|
+
'expires_utc' => '1234567890',
|
20
|
+
'name' => 'NAME',
|
21
|
+
'value' => 'VALUE'})
|
22
|
+
@extractor = CookieExtractor::ChromeCookieExtractor.new('filename')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should close the db when finished" do
|
26
|
+
@fake_cookie_db.should_receive(:close)
|
27
|
+
@extractor.extract
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "with a cookie that has a host starting with a dot" do
|
32
|
+
before :each do
|
33
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
34
|
+
{ 'host_key' => '.dallien.net',
|
35
|
+
'path' => '/',
|
36
|
+
'secure' => '0',
|
37
|
+
'expires_utc' => '1234567890',
|
38
|
+
'name' => 'NAME',
|
39
|
+
'value' => 'VALUE'})
|
40
|
+
@extractor = CookieExtractor::ChromeCookieExtractor.new('filename')
|
41
|
+
@result = @extractor.extract
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return one cookie string" do
|
45
|
+
@result.size.should == 1
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should put TRUE in the domain wide field" do
|
49
|
+
cookie_string = @result.first
|
50
|
+
cookie_string.split("\t")[1].should == "TRUE"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should build the correct cookie string" do
|
54
|
+
cookie_string = @result.first
|
55
|
+
cookie_string.should ==
|
56
|
+
".dallien.net\tTRUE\t/\tFALSE\t1234567890\tNAME\tVALUE"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "with a cookie that has a host not starting with a dot" do
|
61
|
+
before :each do
|
62
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
63
|
+
{ 'host_key' => 'jeff.dallien.net',
|
64
|
+
'path' => '/path',
|
65
|
+
'secure' => '1',
|
66
|
+
'expires_utc' => '1234567890',
|
67
|
+
'name' => 'NAME',
|
68
|
+
'value' => 'VALUE'})
|
69
|
+
@extractor = CookieExtractor::ChromeCookieExtractor.new('filename')
|
70
|
+
@result = @extractor.extract
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return one cookie string" do
|
74
|
+
@result.size.should == 1
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should put FALSE in the domain wide field" do
|
78
|
+
cookie_string = @result.first
|
79
|
+
cookie_string.split("\t")[1].should == "FALSE"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should build the correct cookie string" do
|
83
|
+
cookie_string = @result.first
|
84
|
+
cookie_string.should ==
|
85
|
+
"jeff.dallien.net\tFALSE\t/path\tTRUE\t1234567890\tNAME\tVALUE"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "with a cookie that is not marked as secure" do
|
90
|
+
before :each do
|
91
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
92
|
+
{ 'host_key' => '.dallien.net',
|
93
|
+
'path' => '/',
|
94
|
+
'secure' => '0',
|
95
|
+
'expires_utc' => '1234567890',
|
96
|
+
'name' => 'NAME',
|
97
|
+
'value' => 'VALUE'})
|
98
|
+
@extractor = CookieExtractor::ChromeCookieExtractor.new('filename')
|
99
|
+
@result = @extractor.extract
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should put FALSE in the secure field" do
|
103
|
+
cookie_string = @result.first
|
104
|
+
cookie_string.split("\t")[3].should == "FALSE"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "with a cookie that is marked as secure" do
|
109
|
+
before :each do
|
110
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
111
|
+
{ 'host_key' => '.dallien.net',
|
112
|
+
'path' => '/',
|
113
|
+
'secure' => '1',
|
114
|
+
'expires_utc' => '1234567890',
|
115
|
+
'name' => 'NAME',
|
116
|
+
'value' => 'VALUE'})
|
117
|
+
@extractor = CookieExtractor::ChromeCookieExtractor.new('filename')
|
118
|
+
@result = @extractor.extract
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should put TRUE in the secure field" do
|
122
|
+
cookie_string = @result.first
|
123
|
+
cookie_string.split("\t")[3].should == "TRUE"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe CookieExtractor::FirefoxCookieExtractor do
|
4
|
+
before :each do
|
5
|
+
@fake_cookie_db = double("cookie database",
|
6
|
+
:results_as_hash= => true,
|
7
|
+
:close => true)
|
8
|
+
SQLite3::Database.should_receive(:new).
|
9
|
+
with('filename').
|
10
|
+
and_return(@fake_cookie_db)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "opening and closing a sqlite db" do
|
14
|
+
before :each do
|
15
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
16
|
+
{'host' => '.dallien.net',
|
17
|
+
'path' => '/',
|
18
|
+
'isSecure' => '0',
|
19
|
+
'expiry' => '1234567890',
|
20
|
+
'name' => 'NAME',
|
21
|
+
'value' => 'VALUE'})
|
22
|
+
@extractor = CookieExtractor::FirefoxCookieExtractor.new('filename')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should close the db when finished" do
|
26
|
+
@fake_cookie_db.should_receive(:close)
|
27
|
+
@extractor.extract
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "with a cookie that has a host starting with a dot" do
|
32
|
+
before :each do
|
33
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
34
|
+
{'host' => '.dallien.net',
|
35
|
+
'path' => '/',
|
36
|
+
'isSecure' => '0',
|
37
|
+
'expiry' => '1234567890',
|
38
|
+
'name' => 'NAME',
|
39
|
+
'value' => 'VALUE'})
|
40
|
+
@extractor = CookieExtractor::FirefoxCookieExtractor.new('filename')
|
41
|
+
@result = @extractor.extract
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return one cookie string" do
|
45
|
+
@result.size.should == 1
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should put TRUE in the domain wide field" do
|
49
|
+
cookie_string = @result.first
|
50
|
+
cookie_string.split("\t")[1].should == "TRUE"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should put FALSE in the secure field" do
|
54
|
+
cookie_string = @result.first
|
55
|
+
cookie_string.split("\t")[3].should == "FALSE"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should build the correct cookie string" do
|
59
|
+
cookie_string = @result.first
|
60
|
+
cookie_string.should ==
|
61
|
+
".dallien.net\tTRUE\t/\tFALSE\t1234567890\tNAME\tVALUE"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "with a cookie that has a host not starting with a dot" do
|
66
|
+
before :each do
|
67
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
68
|
+
{ 'host' => 'jeff.dallien.net',
|
69
|
+
'path' => '/path',
|
70
|
+
'isSecure' => '1',
|
71
|
+
'expiry' => '1234567890',
|
72
|
+
'name' => 'NAME',
|
73
|
+
'value' => 'VALUE'})
|
74
|
+
@extractor = CookieExtractor::FirefoxCookieExtractor.new('filename')
|
75
|
+
@result = @extractor.extract
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should return one cookie string" do
|
79
|
+
@result.size.should == 1
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should put FALSE in the domain wide field" do
|
83
|
+
cookie_string = @result.first
|
84
|
+
cookie_string.split("\t")[1].should == "FALSE"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should put TRUE in the secure field" do
|
88
|
+
cookie_string = @result.first
|
89
|
+
cookie_string.split("\t")[3].should == "TRUE"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should build the correct cookie string" do
|
93
|
+
cookie_string = @result.first
|
94
|
+
cookie_string.should ==
|
95
|
+
"jeff.dallien.net\tFALSE\t/path\tTRUE\t1234567890\tNAME\tVALUE"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "with a cookie that is not marked as secure" do
|
100
|
+
before :each do
|
101
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
102
|
+
{'host' => '.dallien.net',
|
103
|
+
'path' => '/',
|
104
|
+
'isSecure' => '0',
|
105
|
+
'expiry' => '1234567890',
|
106
|
+
'name' => 'NAME',
|
107
|
+
'value' => 'VALUE'})
|
108
|
+
@extractor = CookieExtractor::FirefoxCookieExtractor.new('filename')
|
109
|
+
@result = @extractor.extract
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should put FALSE in the secure field" do
|
113
|
+
cookie_string = @result.first
|
114
|
+
cookie_string.split("\t")[3].should == "FALSE"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "with a cookie that is marked as secure" do
|
119
|
+
before :each do
|
120
|
+
@fake_cookie_db.should_receive(:execute).and_yield(
|
121
|
+
{'host' => '.dallien.net',
|
122
|
+
'path' => '/',
|
123
|
+
'isSecure' => '1',
|
124
|
+
'expiry' => '1234567890',
|
125
|
+
'name' => 'NAME',
|
126
|
+
'value' => 'VALUE'})
|
127
|
+
@extractor = CookieExtractor::FirefoxCookieExtractor.new('filename')
|
128
|
+
@result = @extractor.extract
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should put TRUE in the secure field" do
|
132
|
+
cookie_string = @result.first
|
133
|
+
cookie_string.split("\t")[3].should == "TRUE"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coookies
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matias Fernandez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
description: Extract cookies from Firefox, Chrome or Chromium sqlite databases into
|
42
|
+
a wget-compatible cookies.txt file.
|
43
|
+
email:
|
44
|
+
- matiasfmolinari@gmail.com
|
45
|
+
executables:
|
46
|
+
- cookie_extractor
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".gitignore"
|
51
|
+
- ".rvmrc"
|
52
|
+
- CHANGES.md
|
53
|
+
- Gemfile
|
54
|
+
- Gemfile.lock
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/cookie_extractor
|
58
|
+
- cookie_extractor.gemspec
|
59
|
+
- lib/cookie_extractor.rb
|
60
|
+
- lib/cookie_extractor/browser_detector.rb
|
61
|
+
- lib/cookie_extractor/chrome_cookie_extractor.rb
|
62
|
+
- lib/cookie_extractor/common.rb
|
63
|
+
- lib/cookie_extractor/firefox_cookie_extractor.rb
|
64
|
+
- lib/cookie_extractor/version.rb
|
65
|
+
- spec/browser_detector_spec.rb
|
66
|
+
- spec/chrome_cookie_extractor_spec.rb
|
67
|
+
- spec/cookie_extractor_spec.rb
|
68
|
+
- spec/firefox_cookie_extractor_spec.rb
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
homepage:
|
71
|
+
licenses: []
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project: cookie_extractor
|
89
|
+
rubygems_version: 2.0.14.1
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Create cookies.txt from Firefox or Chrome/Chromium cookies
|
93
|
+
test_files:
|
94
|
+
- spec/browser_detector_spec.rb
|
95
|
+
- spec/chrome_cookie_extractor_spec.rb
|
96
|
+
- spec/cookie_extractor_spec.rb
|
97
|
+
- spec/firefox_cookie_extractor_spec.rb
|
98
|
+
- spec/spec_helper.rb
|