git.ucc.asn.au
/
matches
/
MCTX3420.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
58361c9
)
Switch back to HTTP status codes for fastcgi + update unit tests
author
Jeremy Tan
<
[email protected]
>
Thu, 29 Aug 2013 01:28:44 +0000
(09:28 +0800)
committer
Jeremy Tan
<
[email protected]
>
Thu, 29 Aug 2013 01:28:44 +0000
(09:28 +0800)
nginx-configs/sites-enabled/mctxconfig
patch
|
blob
|
history
server/fastcgi.h
patch
|
blob
|
history
testing/qunit/index.html
patch
|
blob
|
history
testing/qunit/unit-tests.js
patch
|
blob
|
history
diff --git
a/nginx-configs/sites-enabled/mctxconfig
b/nginx-configs/sites-enabled/mctxconfig
index
541f6d1
..
dfdf2b9
100644
(file)
--- a/
nginx-configs/sites-enabled/mctxconfig
+++ b/
nginx-configs/sites-enabled/mctxconfig
@@
-70,18
+70,17
@@
server {
deny all;
}
deny all;
}
- #Login area
- location ^~ /api/login {
- auth_basic "Restricted Access";
- auth_basic_user_file /usr/share/nginx/access/.htpasswd;
-
- fastcgi_pass 127.0.0.1:9005;
- fastcgi_param DOCUMENT_URI_LOCAL login;
- include fastcgi_params;
- }
-
#MCTX API
location /api {
#MCTX API
location /api {
+ #Login area
+ location ^~ /api/login {
+ auth_basic "Restricted Access";
+ auth_basic_user_file /usr/share/nginx/access/.htpasswd;
+
+ fastcgi_pass 127.0.0.1:9005;
+ fastcgi_param DOCUMENT_URI_LOCAL login;
+ include fastcgi_params;
+ }
location ~ ^/api/?([^?]*) {
fastcgi_pass 127.0.0.1:9005;
fastcgi_param DOCUMENT_URI_LOCAL $1;
location ~ ^/api/?([^?]*) {
fastcgi_pass 127.0.0.1:9005;
fastcgi_param DOCUMENT_URI_LOCAL $1;
diff --git
a/server/fastcgi.h
b/server/fastcgi.h
index
1efdef7
..
3030b75
100644
(file)
--- a/
server/fastcgi.h
+++ b/
server/fastcgi.h
@@
-6,11
+6,11
@@
#ifndef _FASTCGI_H
#define _FASTCGI_H
#ifndef _FASTCGI_H
#define _FASTCGI_H
-/**Status codes that fcgi module handlers can return**/
+/**
(HTTP)
Status codes that fcgi module handlers can return**/
typedef enum StatusCodes {
typedef enum StatusCodes {
- STATUS_OK = 0,
- STATUS_ERROR =
-1
,
- STATUS_UNAUTHORIZED =
-2
+ STATUS_OK =
20
0,
+ STATUS_ERROR =
400
,
+ STATUS_UNAUTHORIZED =
401
} StatusCodes;
typedef struct FCGIContext FCGIContext;
} StatusCodes;
typedef struct FCGIContext FCGIContext;
diff --git
a/testing/qunit/index.html
b/testing/qunit/index.html
index
4f4dcfe
..
e666fce
100644
(file)
--- a/
testing/qunit/index.html
+++ b/
testing/qunit/index.html
@@
-4,12
+4,12
@@
<meta charset="utf-8">
<title>MCTX3420 2013 Server API unit tests</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
<meta charset="utf-8">
<title>MCTX3420 2013 Server API unit tests</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
- </head>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
+ <script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
+ </head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
- <script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<script src="unit-tests.js"></script>
</body>
</html>
\ No newline at end of file
<script src="unit-tests.js"></script>
</body>
</html>
\ No newline at end of file
diff --git
a/testing/qunit/unit-tests.js
b/testing/qunit/unit-tests.js
index
c16b8c9
..
b7ba7e1
100644
(file)
--- a/
testing/qunit/unit-tests.js
+++ b/
testing/qunit/unit-tests.js
@@
-11,14
+11,31
@@
var api = location.protocol + "//" + location.host + "/api/";
/**
* Sends an AJAX query to the API
/**
* Sends an AJAX query to the API
+ * query(module, username, password, callback);
+ * query(module, callback);
+ * query(module, opts, callback);
+ * query(module, opts, username, password, callback);
* @param {string} module The name of the module to be queried
* @param {Object} opts Object containing parameters to pass to module
* @param {string} module The name of the module to be queried
* @param {Object} opts Object containing parameters to pass to module
- * @param {function} callback Function that receives JSON data
* @param {string} username Optional
* @param {string} password Required if username specified
* @param {string} username Optional
* @param {string} password Required if username specified
+ * @param {function} callback Function that receives JSON data
* @returns JSON data
*/
* @returns JSON data
*/
-function query(module, opts, callback, username, password) {
+function query(module, opts, username, password, callback) {
+ if (typeof opts === 'string') {
+ callback = password;
+ password = username;
+ username = opts;
+ opts = undefined;
+ } else if (typeof opts === 'function') {
+ callback = opts;
+ opts = undefined;
+ } else if (typeof username === 'function') {
+ callback = username;
+ username = undefined;
+ }
+
function buildQuery(opts) {
var result = "?";
var first = true;
function buildQuery(opts) {
var result = "?";
var first = true;
@@
-38,34
+55,58
@@
function query(module, opts, callback, username, password) {
if (opts)
queryurl += buildQuery(opts);
if (opts)
queryurl += buildQuery(opts);
+ var authfunc;
+ if (username) {
+ authfunc = function(xhr) {
+ xhr.setRequestHeader("Authorization",
+ "Basic " + btoa(username + ":" + password));
+ };
+ }
+
$.ajax({
url: queryurl,
type: 'GET',
dataType: 'json',
$.ajax({
url: queryurl,
type: 'GET',
dataType: 'json',
- beforeSend: !username ? undefined : function (xhr) {
- xhr.setRequestHeader("Authorization",
- "Basic " + btoa(username + ":" + password));
- }
+ beforeSend: authfunc
}).done(callback)
.fail(function(jqXHR) {
}).done(callback)
.fail(function(jqXHR) {
- if (jqXHR.status === 400) {
- callback($.parseJSON(jqXHR.responseText));
+ //Note:Callback must be called so the QUnit test can run.
+ if (jqXHR.status !== 400) {
+ callback({"status" : jqXHR.status, "description" : jqXHR.statusText});
} else {
} else {
- callback({status:-999,
- description: jqXHR.status.toString() + " " + jqXHR.responseText});
+ try {
+ callback($.parseJSON(jqXHR.responseText));
+ } catch (err) {
+ callback({"status" : jqXHR.status, "description" : jqXHR.statusText});
+ }
}
});
}
}
});
}
-QUnit.test("API Existence", function () {
- stop(); //?????
- query("test", undefined, function(data) {
+
+QUnit.asyncTest("API Existence", function () {
+ query("test", function(data) {
+ start();
+ //TODO:Change fastcgi error codes
equal(parseInt(data.status, 10), -1, "Nonexistent module"); //Magic numbers!
equal(parseInt(data.status, 10), -1, "Nonexistent module"); //Magic numbers!
+ });
+});
+
+QUnit.asyncTest("Login test", function() {
+ query("login", {"force" : true}, "mctxadmin", "admin", function(data) {
start();
start();
- });
+ equal(parseInt(data.status, 10), 0, "Login ok"); //Magic numbers!
+ });
+});
+
+QUnit.test("Sensors module", function() {
+
+});
+
+/*QUnit.test("Login module", function () {
+
+});*/
- /*query("version", undefined, function (data) {
- assert.equal(data.status, 0);
- });*/
+QUnit.test("Access control", function () {
});
\ No newline at end of file
});
\ No newline at end of file
UCC
git Repository :: git.ucc.asn.au