@@ -151,56 +151,57 @@ describe("readChromiumCookieDatabase", () => {
151151 } ) . pipe ( Effect . provide ( NodeServices . layer ) , Effect . scoped ) ,
152152 ) ;
153153
154- it . effect ( "reads plaintext, encrypted, and genuinely empty cookie values" , ( ) =>
155- Effect . gen ( function * ( ) {
156- const fileSystem = yield * FileSystem . FileSystem ;
157- const directory = yield * fileSystem . makeTempDirectoryScoped ( {
158- prefix : "t3code-chromium-cookies-" ,
159- } ) ;
160- const filename = `${ directory } /Cookies` ;
161- const key = Buffer . from ( "0123456789abcdef" ) ;
154+ it . effect . each ( [ 14 , 24 ] ) (
155+ "imports mixed TEXT and BLOB cookie values, including empty values, in schema %i" ,
156+ ( schemaVersion ) =>
157+ Effect . gen ( function * ( ) {
158+ const fileSystem = yield * FileSystem . FileSystem ;
159+ const directory = yield * fileSystem . makeTempDirectoryScoped ( {
160+ prefix : "t3code-chromium-cookies-" ,
161+ } ) ;
162+ const filename = `${ directory } /Cookies` ;
163+ const key = Buffer . from ( "0123456789abcdef" ) ;
164+ const host = "secure.example" ;
165+ const value = "stored encrypted" ;
166+ const payload =
167+ schemaVersion >= 24
168+ ? Buffer . concat ( [
169+ NodeCrypto . createHash ( "sha256" ) . update ( host ) . digest ( ) ,
170+ Buffer . from ( value ) ,
171+ ] )
172+ : Buffer . from ( value ) ;
173+ const encrypted = encryptV10 ( payload , key ) ;
162174
163- yield * Effect . gen ( function * ( ) {
164- const sql = yield * SqlClient . SqlClient ;
165- yield * sql `create table meta (key text primary key, value text not null)` ;
166- yield * sql `insert into meta values ('version', 23)` ;
167- yield * sql `
168- create table cookies (
169- host_key text not null,
170- name text not null,
171- value text not null,
172- encrypted_value blob not null,
173- path text not null,
174- expires_utc integer not null,
175- is_secure integer not null,
176- is_httponly integer not null,
177- samesite integer not null,
178- top_frame_site_key text not null default ''
179- )
180- ` ;
181- yield * sql `
182- insert into cookies (host_key, name, value, encrypted_value, path, expires_utc, is_secure, is_httponly, samesite) values
183- ('plain.example', 'plain', 'stored plaintext', ${ new Uint8Array ( ) } , '/', 0, 0, 0, -1)
184- ` ;
185- yield * sql `
186- insert into cookies (host_key, name, value, encrypted_value, path, expires_utc, is_secure, is_httponly, samesite) values
187- ('secure.example', 'encrypted', '', ${ encryptV10 ( "stored encrypted" , key ) } , '/', 0, 1, 1, 2)
188- ` ;
189- yield * sql `
190- insert into cookies (host_key, name, value, encrypted_value, path, expires_utc, is_secure, is_httponly, samesite) values
191- ('empty.example', 'empty', '', ${ new Uint8Array ( ) } , '/', 0, 0, 0, 0)
192- ` ;
193- } ) . pipe ( Effect . provide ( NodeSqliteClient . layer ( { filename } ) ) ) ;
175+ yield * Effect . gen ( function * ( ) {
176+ const sql = yield * SqlClient . SqlClient ;
177+ yield * sql `create table meta (key text primary key, value text not null)` ;
178+ yield * sql `insert into meta values ('version', ${ schemaVersion } )` ;
179+ yield * sql `create table cookies (
180+ host_key text not null, name text not null, value text not null,
181+ encrypted_value blob not null, path text not null, expires_utc integer not null,
182+ is_secure integer not null, is_httponly integer not null, samesite integer not null
183+ )` ;
184+ if ( schemaVersion >= 15 ) {
185+ yield * sql `alter table cookies add column top_frame_site_key text not null default ''` ;
186+ }
187+ yield * sql `insert into cookies
188+ (host_key, name, value, encrypted_value, path, expires_utc, is_secure, is_httponly, samesite) values
189+ ('plain.example', 'plain', 'stored plaintext', '', '/', 0, 0, 0, -1),
190+ (${ host } , 'text-encrypted', '', cast(${ encrypted } as text), '/', 0, 1, 1, 2),
191+ (${ host } , 'blob-encrypted', '', ${ encrypted } , '/', 0, 1, 1, 2),
192+ ('empty.example', 'empty', '', ${ new Uint8Array ( ) } , '/', 0, 0, 0, 0)` ;
193+ } ) . pipe ( Effect . provide ( NodeSqliteClient . layer ( { filename } ) ) ) ;
194194
195- const result = yield * readChromiumCookieDatabase ( filename , { cbcV10 : key } , "darwin" ) ;
195+ const result = yield * readChromiumCookieDatabase ( filename , { cbcV10 : key } , "darwin" ) ;
196196
197- expect ( result . undecryptable ) . toBe ( 0 ) ;
198- expect ( result . cookies . map ( ( { name, value } ) => ( { name, value } ) ) ) . toEqual ( [
199- { name : "plain" , value : "stored plaintext" } ,
200- { name : "encrypted" , value : "stored encrypted" } ,
201- { name : "empty" , value : "" } ,
202- ] ) ;
203- } ) . pipe ( Effect . provide ( NodeServices . layer ) , Effect . scoped ) ,
197+ expect ( result . undecryptable ) . toBe ( 0 ) ;
198+ expect ( result . cookies . map ( ( { name, value } ) => ( { name, value } ) ) ) . toEqual ( [
199+ { name : "plain" , value : "stored plaintext" } ,
200+ { name : "text-encrypted" , value } ,
201+ { name : "blob-encrypted" , value } ,
202+ { name : "empty" , value : "" } ,
203+ ] ) ;
204+ } ) . pipe ( Effect . provide ( NodeServices . layer ) , Effect . scoped ) ,
204205 ) ;
205206
206207 it . effect ( "enforces domain binding only for schema 24 and newer" , ( ) =>
0 commit comments