11package hoverctl_suite
22
33import (
4- "github.com/antonholmquist/jason "
4+ "io "
55 "io/ioutil"
66 "strconv"
7+ "strings"
8+
9+ "github.com/antonholmquist/jason"
710
811 "github.com/SpectoLabs/hoverfly/core/authentication/backends"
912 "github.com/SpectoLabs/hoverfly/functional-tests"
@@ -327,7 +330,21 @@ var _ = Describe("hoverctl `start`", func() {
327330 })
328331 })
329332
330- Context ("with pac-file" , func () {
333+ Context ("with enable-middleware-api" , func () {
334+ It ("enables middleware API when flag is provided" , func () {
335+ output := functional_tests .Run (hoverctlBinary , "start" , "--enable-middleware-api" )
336+ Expect (output ).To (ContainSubstring ("Hoverfly is now running" ))
337+
338+ // Attempt to set middleware via Admin API should be allowed (200)
339+ req := sling .New ().Put ("http://localhost:8888/api/v2/hoverfly/middleware" )
340+ // Use a valid echo middleware that reads from STDIN and outputs the JSON payload unchanged
341+ req .Body (strings .NewReader (`{"binary":"ruby", "script":"#!/usr/bin/env ruby\n# encoding: utf-8\nwhile payload = STDIN.gets\nnext unless payload\n\nSTDOUT.puts payload\nend"}` ))
342+ res := functional_tests .DoRequest (req )
343+ Expect (res .StatusCode ).To (Equal (200 ))
344+ })
345+ })
346+
347+ Context ("with pac-file" , func () {
331348 BeforeEach (func () {
332349 })
333350
@@ -338,7 +355,7 @@ var _ = Describe("hoverctl `start`", func() {
338355
339356 response := functional_tests .DoRequest (sling .New ().Get ("http://localhost:8888/api/v2/hoverfly/pac" ))
340357 Expect (response .StatusCode ).To (Equal (200 ))
341- responseBody , err := ioutil .ReadAll (response .Body )
358+ responseBody , err := io .ReadAll (response .Body )
342359 Expect (err ).To (BeNil ())
343360 Expect (string (responseBody )).To (ContainSubstring (`function FindProxyForURL(url, host) {` ))
344361 })
0 commit comments