Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router test: config template: don't match against the whole file #311

Merged

Conversation

alebedev87
Copy link
Contributor

@alebedev87 alebedev87 commented Jun 18, 2021

Improvement to the test introduced in #307.
The check for the presence of config snippets is not made against the whole config file anymore.
It now searches only the backend part of the config corresponding to the route.
This helps to avoid the false positives and negatives.

Note the usage of https://github.com/haproxytech/config-parser

@openshift-ci openshift-ci bot requested review from candita and knobunc June 18, 2021 17:41
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 18, 2021
@alebedev87 alebedev87 force-pushed the hsts-and-config-parser branch from 044c3fc to 52e34df Compare June 18, 2021 17:47
@alebedev87
Copy link
Contributor Author

/assign @Miciah @candita

@alebedev87
Copy link
Contributor Author

/retest

edgeBePrefix = "be_edge_http"
)

// ConfigParser is a primitive HAProxy config parser.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether you looked at https://github.com/haproxytech/config-parser and if that would do what we need.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I didn't, I wasn't expecting any golang libs from HAProxy community. But this one is even from the upstream! Thanks a lot for the advice. This module looks very promising:

$ cat config.cfg  | grep -A 15 be_edge_http:test-route:hello-openshift2
backend be_edge_http:test-route:hello-openshift2
  mode http
  option redispatch
  option forwardfor
  balance 

  timeout check 5000ms
  http-request add-header X-Forwarded-Host %[req.hdr(host)]
  http-request add-header X-Forwarded-Port %[dst_port]
  http-request add-header X-Forwarded-Proto http if !{ ssl_fc }
  http-request add-header X-Forwarded-Proto https if { ssl_fc }
  http-request add-header X-Forwarded-Proto-Version h2 if { ssl_fc_alpn -i h2 }
  http-request add-header Forwarded for=%[src];host=%[req.hdr(host)];proto=%[req.hdr(X-Forwarded-Proto)]
  http-response set-header Strict-Transport-Security 'max-age=99999;includesubdomain'
  cookie f7e936ebe97cd64e8c888d1eba08cb29 insert indirect nocache httponly secure attr SameSite=None
  server pod:hello-openshift-7b8c68587c-mtck6:hello-openshift:8080-tcp:10.217.0.24:8080 10.217.0.24:8080 cookie 97ddca1460eca46376928fd7bcf8c89c weight 256 check inter 5000ms

$ cat main.go 
package main

import (
	"fmt"
	"github.com/haproxytech/config-parser/v4"
	"github.com/haproxytech/config-parser/v4/options"
	"github.com/haproxytech/config-parser/v4/types"
)

func main() {
	p, err := parser.New(options.Path("config.cfg"))
	if err != nil {
		fmt.Println("failed to parse the config:", err)
	}

	data, err := p.Get(parser.Backends, "be_edge_http:test-route:hello-openshift2", "http-response", false)
	if err != nil {
		fmt.Println("failed to get backend:", err)
	}

	responses := data.([]types.HTTPAction)
	for _, r := range responses {
		fmt.Println(r)
	}
}

$ go run main.go 
set-header Strict-Transport-Security 'max-age=99999;includesubdomain'

Let me try to integrate it into my PR.

@alebedev87
Copy link
Contributor Author

/hold

I will try to integrate https://github.com/haproxytech/config-parser module instead of the home made parser.

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 2, 2021
@alebedev87
Copy link
Contributor Author

/retest

@alebedev87 alebedev87 force-pushed the hsts-and-config-parser branch 2 times, most recently from d3a5989 to 68ec9dc Compare August 5, 2021 09:10
@alebedev87
Copy link
Contributor Author

/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 5, 2021
@alebedev87
Copy link
Contributor Author

/assign @frobware

@alebedev87
Copy link
Contributor Author

/retest

Copy link
Contributor

@frobware frobware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great that the upstream config parser slips in so easily.

pkg/router/router_test.go Outdated Show resolved Hide resolved
@alebedev87 alebedev87 force-pushed the hsts-and-config-parser branch from 68ec9dc to a4f8427 Compare August 5, 2021 16:42
@frobware
Copy link
Contributor

frobware commented Aug 5, 2021

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 5, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Aug 5, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alebedev87, frobware

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [alebedev87,frobware]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

4 similar comments
@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

27 similar comments
@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest-required

Please review the full test history for this PR and help us cut down flakes.

@frobware
Copy link
Contributor

/skip

@openshift-merge-robot openshift-merge-robot merged commit 6316ee7 into openshift:master Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants