auth.js 886 B

12345678910111213141516171819202122232425262728293031323334353637
  1. var should = require("should")
  2. var request = require('request')
  3. var path = require('path')
  4. var harp = require("../")
  5. describe("basicAuth", function(){
  6. describe("single", function(done){
  7. var projectPath = path.join(__dirname, "apps/auth/single")
  8. before(function(done){
  9. harp.server(projectPath, { port: 8310 }, done)
  10. })
  11. it("should be a protected page", function(done){
  12. request('http://localhost:8310/', function (e, r, b) {
  13. r.statusCode.should.eql(401)
  14. done()
  15. })
  16. })
  17. it("should fetch protected resource with correct creds", function(done){
  18. request({
  19. method: "GET",
  20. url: 'http://localhost:8310/',
  21. auth: {
  22. 'user': 'foo',
  23. 'pass': 'bar'
  24. }
  25. }, function (e, r, b) {
  26. r.statusCode.should.eql(200)
  27. done()
  28. })
  29. })
  30. })
  31. })