MXS-1220: Add PUT support for /maxscale/ resource
The /maxscale/ resource now supports PUT requests which modify core parameters. As not all parameters can be changed at runtime, only modifications to parameters that support runtime configuration are allowed.
This commit is contained in:
@ -19,3 +19,6 @@ do
|
||||
$maxscaledir/bin/maxadmin help >& /dev/null && break
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
# Give MaxScale some time to settle
|
||||
sleep 1
|
||||
|
116
server/core/test/rest-api/test/auth.js
Normal file
116
server/core/test/rest-api/test/auth.js
Normal file
@ -0,0 +1,116 @@
|
||||
require("../utils.js")()
|
||||
|
||||
|
||||
function set_auth(auth, value) {
|
||||
return request.get(auth + host + "/maxscale")
|
||||
.then(function(resp) {
|
||||
var d = JSON.parse(resp)
|
||||
d.data.attributes.parameters.admin_auth = value;
|
||||
return request.put(auth + host + "/maxscale", { json: d })
|
||||
})
|
||||
.then(function() {
|
||||
return request.get(auth + host + "/maxscale")
|
||||
})
|
||||
.then(function(resp) {
|
||||
var d = JSON.parse(resp)
|
||||
d.data.attributes.parameters.admin_auth.should.equal(value)
|
||||
})
|
||||
}
|
||||
|
||||
describe("Authentication", function() {
|
||||
before(startMaxScale)
|
||||
|
||||
var user1 = {
|
||||
data: {
|
||||
id: "user1",
|
||||
type: "inet",
|
||||
attributes: {
|
||||
password: "pw1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var user2 = {
|
||||
data: {
|
||||
id: "user2",
|
||||
type: "inet",
|
||||
attributes: {
|
||||
password: "pw2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var auth1 = "http://" + user1.data.id + ":" + user1.data.attributes.password + "@"
|
||||
var auth2 = "http://" + user2.data.id + ":" + user2.data.attributes.password + "@"
|
||||
|
||||
it("unauthorized request without authentication", function() {
|
||||
return request.get(base_url + "/maxscale")
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it("authorized request without authentication", function() {
|
||||
return request.get(auth1 + host + "/maxscale")
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it("add user", function() {
|
||||
return request.post(base_url + "/users/inet", { json: user1 })
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it("request created user", function() {
|
||||
return request.get(base_url + "/users/inet/" + user1.data.id)
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it("enable authentication", function() {
|
||||
return set_auth(auth1, true).should.be.fulfilled
|
||||
})
|
||||
|
||||
it("unauthorized request with authentication", function() {
|
||||
return request.get(base_url + "/maxscale").auth()
|
||||
.should.be.rejected
|
||||
})
|
||||
|
||||
it("authorized request with authentication", function() {
|
||||
return request.get(auth1 + host + "/maxscale")
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it("replace user", function() {
|
||||
return request.post(auth1 + host + "/users/inet", { json: user2 })
|
||||
.then(function() {
|
||||
return request.get(auth1 + host + "/users/inet/" + user2.data.id)
|
||||
})
|
||||
.then(function() {
|
||||
return request.delete(auth1 + host + "/users/inet/" + user1.data.id)
|
||||
})
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it("request with wrong user", function() {
|
||||
return request.get(auth1 + host + "/maxscale")
|
||||
.should.be.rejected
|
||||
})
|
||||
|
||||
it("request with correct user", function() {
|
||||
return request.get(auth2 + host + "/maxscale")
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it("disable authentication", function() {
|
||||
return set_auth(auth2, false).should.be.fulfilled
|
||||
})
|
||||
|
||||
it("unauthorized request without authentication ", function() {
|
||||
return request.get(base_url + "/maxscale/logs")
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it("authorized request without authentication", function() {
|
||||
return request.get(auth2 + host + "/maxscale")
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
after(stopMaxScale)
|
||||
});
|
39
server/core/test/rest-api/test/core.js
Normal file
39
server/core/test/rest-api/test/core.js
Normal file
@ -0,0 +1,39 @@
|
||||
require("../utils.js")()
|
||||
|
||||
|
||||
function set_value(key, value) {
|
||||
return request.get(base_url + "/maxscale")
|
||||
.then(function(resp) {
|
||||
var d = JSON.parse(resp)
|
||||
d.data.attributes.parameters[key] = value;
|
||||
return request.put(base_url + "/maxscale", { json: d })
|
||||
})
|
||||
.then(function() {
|
||||
return request.get(base_url + "/maxscale")
|
||||
})
|
||||
.then(function(resp) {
|
||||
var d = JSON.parse(resp)
|
||||
d.data.attributes.parameters[key].should.equal(value)
|
||||
})
|
||||
}
|
||||
|
||||
describe("Core Parameters", function() {
|
||||
before(startMaxScale)
|
||||
|
||||
it("auth_connect_timeout", function() {
|
||||
return set_value("auth_connect_timeout", 10)
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it("auth_read_timeout", function() {
|
||||
return set_value("auth_read_timeout", 10)
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
it("auth_write_timeout", function() {
|
||||
return set_value("auth_write_timeout", 10)
|
||||
.should.be.fulfilled
|
||||
})
|
||||
|
||||
after(stopMaxScale)
|
||||
});
|
@ -4,7 +4,7 @@ require("../utils.js")()
|
||||
describe("Users", function() {
|
||||
before(startMaxScale)
|
||||
|
||||
user = {
|
||||
var user = {
|
||||
data: {
|
||||
id: "user1",
|
||||
type: "inet",
|
||||
|
@ -420,7 +420,8 @@ module.exports = function() {
|
||||
this.ajv = new Ajv({$data: true, allErrors: true, extendRefs: true, verbose: true})
|
||||
this.validate_func = ajv.compile(json_api_schema)
|
||||
this.validate = validate_json
|
||||
this.base_url = "http://localhost:8989/v1"
|
||||
this.host = "localhost:8989/v1"
|
||||
this.base_url = "http://" + this.host
|
||||
this.startMaxScale = function(done) {
|
||||
child_process.execFile("./before.sh", function(err, stdout, stderr) {
|
||||
if (process.env.MAXSCALE_DIR == null) {
|
||||
|
Reference in New Issue
Block a user