<commit_before>should = require "should"
sinon = require "sinon"
https = require "https"
fs = require "fs"
request = require "supertest"
config = require "../lib/config"

server = require "../lib/server"

describe "Integration Tests", ->

	it.skip "should forward a request to the configured routes if the application is authenticated and authorised", (done) ->
		server.start 5001, 5000
		options =
			host: "localhost"
			path: "sample/request"
			port: 5000
			cert: fs.readFileSync "tls/cert.pem"
			key:  fs.readFileSync "tls/key.pem"

		https.request options, (req, res) ->
			res.statusCode.should.be 201

	describe "Basic Auth", ->
		describe "with no credentials", ->
			it "should `throw` 401", (done) ->
				server.start 5001, null, ->
					console.log "started server"
					request("http://localhost:5001")
						.get('/sample/api')
						.expect(401)
						.end (err, res) ->
							server.stop done

		describe.skip "with incorrect credentials", ->
			it "should `throw` 401", (done) ->
				koaMiddleware.setupApp (app) ->
					request(app.listen())
						.get('/sample/api')
						.auth('incorrect_user', 'incorrect_password')
						.expect(401)
						.end done
		
		describe.skip "with correct credentials", ->
			it "should return 200 OK", (done) ->
				koaMiddleware.setupApp (app) ->
					request(app.listen())
						.get('/sample/api')
						.auth('testApp', 'password')
						.expect(200)
						.end done<commit_msg>Fixed other basic auth integration tests<commit_after>should = require "should"
sinon = require "sinon"
https = require "https"
fs = require "fs"
request = require "supertest"
config = require "../lib/config"

server = require "../lib/server"

describe "Integration Tests", ->

	it.skip "should forward a request to the configured routes if the application is authenticated and authorised", (done) ->
		server.start 5001, 5000
		options =
			host: "localhost"
			path: "sample/request"
			port: 5000
			cert: fs.readFileSync "tls/cert.pem"
			key:  fs.readFileSync "tls/key.pem"

		https.request options, (req, res) ->
			res.statusCode.should.be 201

	describe "Basic Auth", ->
		describe "with no credentials", ->
			it "should `throw` 401", (done) ->
				server.start 5001, null, ->
					console.log "started server"
					request("http://localhost:5001")
						.get('/sample/api')
						.expect(401)
						.end (err, res) ->
							server.stop ->
								if err
									done err
								else
									done()

		describe "with incorrect credentials", ->
			it "should `throw` 401", (done) ->
				server.start 5001, null, ->
					console.log "started server"
					request("http://localhost:5001")
						.get('/sample/api')
						.expect(401)
						.end (err, res) ->
							server.stop ->
								if err
									done err
								else
									done()
		
		describe "with correct credentials", ->
			it "should return 200 OK", (done) ->
				server.start 5001, null, ->
					console.log "started server"
					request("http://localhost:5001")
						.get('/sample/api')
						.expect(200)
						.end (err, res) ->
							server.stop ->
								if err
									done err
								else
									done()
{'fraction_non_alphanumeric': 0.14367816091954022, 'fraction_numerical': 0.031289910600255426, 'mean_word_length': 2.5241844769403823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7362718', 'n_tokens_mistral': 1386, 'n_tokens_neox': 959, 'n_words': 281}