Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Bryan Kaperick
jio
Commits
6f1464b1
Commit
6f1464b1
authored
Jun 25, 2018
by
Bryan Kaperick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a check to put() to make sure id is not in same format as a timestamp.
parent
79d7f77b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
58 deletions
+29
-58
src/jio.storage/historystorage.js
src/jio.storage/historystorage.js
+15
-3
test/jio.storage/historystorage.tests.js
test/jio.storage/historystorage.tests.js
+14
-55
No files found.
src/jio.storage/historystorage.js
View file @
6f1464b1
...
...
@@ -13,7 +13,14 @@
//timestamp = Date.now().toString();
timestamp
=
time
.
toString
();
return
timestamp
+
"
-
"
+
uuid
;
};
},
looks_like_timestamp
=
function
(
id
)
{
//1529928772623-02e6
//A timestamp is of the form
//"[13 digit number]-[4 numbers/lowercase letters]"
var
re
=
/^
[
0-9
]{13}
-
[
a-z0-9
]{4}
$/
;
return
re
.
test
(
id
);
};
/**
...
...
@@ -90,8 +97,7 @@
if
(
error
.
status_code
===
400
&&
error
instanceof
jIO
.
util
.
jIOError
)
{
throw
new
jIO
.
util
.
jIOError
(
"
HistoryStorage: cannot find object '
"
+
id_in
+
"
'
"
,
"
HistoryStorage: cannot find object '
"
+
id_in
+
"
'
"
,
404
);
}
...
...
@@ -112,6 +118,12 @@
422
);
}
if
(
looks_like_timestamp
(
id
))
{
throw
new
jIO
.
util
.
jIOError
(
"
Document cannot have id of the same form as a timestamp
"
,
422
);
}
var
timestamp
=
unique_timestamp
(
Date
.
now
()),
metadata
=
{
// XXX: remove this attribute once query can sort_on id
...
...
test/jio.storage/historystorage.tests.js
View file @
6f1464b1
...
...
@@ -60,6 +60,7 @@
});
}
});
test
(
"
Testing proper adding/removing attachments
"
,
function
()
{
stop
();
...
...
@@ -172,7 +173,6 @@
.
always
(
function
()
{
start
();
});
});
test
(
"
Correctness of allAttachments method
"
,
function
()
{
stop
();
...
...
@@ -304,59 +304,6 @@
.
always
(
function
()
{
start
();
});
});
test
(
"
Correctness of allAttachments method
"
,
function
()
{
stop
();
expect
(
4
);
var
jio
=
this
.
jio
,
timestamps
=
jio
.
__storage
.
_timestamps
,
blob1
=
this
.
blob1
,
blob2
=
this
.
blob2
,
other_blob1
=
this
.
other_blob
,
other_blob2
=
new
Blob
([
'
asdf
'
]);
putFullDoc
(
jio
,
"
doc
"
,
{},
"
data
"
,
blob1
)
.
push
(
function
()
{
return
jio
.
putAttachment
(
"
doc
"
,
"
data
"
,
blob2
);
})
.
push
(
function
()
{
return
jio
.
putAttachment
(
"
doc
"
,
"
other_data
"
,
other_blob1
);
})
.
push
(
function
()
{
return
jio
.
putAttachment
(
"
doc
"
,
"
other_data
"
,
other_blob2
);
})
.
push
(
function
()
{
return
jio
.
getAttachment
(
timestamps
.
doc
.
data
[
0
],
"
data
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
blob1
,
"
Get old version of first attachment
"
);
return
jio
.
getAttachment
(
timestamps
.
doc
.
data
[
1
],
"
data
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
blob2
,
"
Get current version of first attachment
"
);
return
jio
.
getAttachment
(
timestamps
.
doc
.
other_data
[
0
],
"
other_data
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
other_blob1
,
"
Get old version of second attachment
"
);
return
jio
.
getAttachment
(
timestamps
.
doc
.
other_data
[
1
],
"
other_data
"
);
})
.
push
(
function
(
result
)
{
deepEqual
(
result
,
other_blob2
,
"
Get current version of second attachment
"
);
})
.
fail
(
function
(
error
)
{
//console.log(error);
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// Querying older revisions
...
...
@@ -395,7 +342,7 @@
test
(
"
Handling bad input
"
,
function
()
{
stop
();
expect
(
4
);
expect
(
6
);
var
jio
=
this
.
jio
,
BADINPUT_ERRCODE
=
422
;
...
...
@@ -427,6 +374,18 @@
"
Can't save a document with a reserved keyword
"
);
})
.
push
(
function
()
{
return
jio
.
put
(
"
1234567891123-ab7d
"
,
{});
})
.
push
(
function
()
{
ok
(
false
,
"
This statement should not be reached
"
);
},
function
(
error
)
{
ok
(
error
instanceof
jIO
.
util
.
jIOError
,
"
Correct type of error
"
);
deepEqual
(
error
.
status_code
,
BADINPUT_ERRCODE
,
"
Can't save a document with a timestamp-formatted id
"
);
})
.
fail
(
function
(
error
)
{
//console.log(error);
ok
(
false
,
error
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment