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

Authz: General Authz (1-4) tests - Fixed authz test issue mentioned in #2770 #3117

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Eeramma
Copy link

@Eeramma Eeramma commented Jun 19, 2024

  1. Added code to handle empty Authz Get() operation in TestAuthz1 & TestAuthz2.
  2. Added code to handle wait-timeout for bidirectional stream Recv API in rpcexec.go & authz.go
  3. Corrected test admin infra id from cafyauto to valid SPIFFE ID.
  4. Added Setup Baseline post reboot to populate policy details.

@Eeramma Eeramma requested review from a team as code owners June 19, 2024 11:46
Copy link

google-cla bot commented Jun 19, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@OpenConfigBot
Copy link

OpenConfigBot commented Jun 26, 2024

Pull Request Functional Test Report for #3117 / 2e7a552

Virtual Devices

Device Test Test Documentation Job Raw Log
Arista cEOS status
Authz: General Authz (1-4) tests
Cisco 8000E status
Authz: General Authz (1-4) tests
Cisco XRd status
Authz: General Authz (1-4) tests
Juniper ncPTX status
Authz: General Authz (1-4) tests
Nokia SR Linux status
Authz: General Authz (1-4) tests
Openconfig Lemming status
Authz: General Authz (1-4) tests

Hardware Devices

Device Test Test Documentation Raw Log
Arista 7808 status
Authz: General Authz (1-4) tests
Cisco 8808 status
Authz: General Authz (1-4) tests
Juniper PTX10008 status
Authz: General Authz (1-4) tests
Nokia 7250 IXR-10e status
Authz: General Authz (1-4) tests

Help

t.Logf("Authz Policy of the Device %s before the Rotate Trigger is %s", dut.Name(), policyBefore.PrettyPrint(t))
defer policyBefore.Rotate(t, dut, uint64(time.Now().Unix()), fmt.Sprintf("v0.%v", (time.Now().UnixNano())), false)
statusmsg, policyBefore := authz.Get(t, dut)
//t.Logf("Message for first authz get %s", msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

random debug log left over?

statusmsg, policyBefore := authz.Get(t, dut)
//t.Logf("Message for first authz get %s", msg)
if statusmsg == nil {
t.Logf("Expected error FAILED_PRECONDITION seen for authz Get Request.")
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be a t.Fatal ? (why continue if you get zero policy on an existing device you expect policy?)

//t.Logf("Message for first authz get %s", msg)
if statusmsg == nil {
t.Logf("Expected error FAILED_PRECONDITION seen for authz Get Request.")
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

what benefit does this else provide?
(genreal advice in golang is to just not else, really ever)

t.Logf("Expected error FAILED_PRECONDITION seen for authz Get Request.")
} else {
t.Logf("Authz Policy of the Device %s before the Rotate Trigger is %s", dut.Name(), policyBefore.PrettyPrint(t))
defer policyBefore.Rotate(t, dut, uint64(time.Now().Unix()), fmt.Sprintf("v0.%v", (time.Now().UnixNano())), false)
Copy link
Contributor

Choose a reason for hiding this comment

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

why defer this?

@@ -46,7 +46,7 @@ const (
type UsersMap map[string]authz.Spiffe

var (
testInfraID = flag.String("test_infra_id", "cafyauto", "SPIFFE-ID used by test Infra ID user for authz operation")
testInfraID = flag.String("test_infra_id", "spiffe://test-abc.foo.bar/xyz/cafyauto", "SPIFFE-ID used by test Infra ID user for authz operation")
Copy link
Contributor

Choose a reason for hiding this comment

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

this user is not in the usersMap - is that intentional? perhaps a comment as to why?

}
if resp.GetCreatedOn() > uint64(time.Now().UnixMicro()) {
t.Errorf("CreatedOn value can not be larger than current time")
statusError, _ := status.FromError(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like you are throwing away an err, why?
(probably a comment like; "ignoring error here for " is good)

if err != nil {
if strings.Contains(err.Error(), "invalid policy") || status.Code(err) == codes.InvalidArgument || strings.Contains(err.Error(), "InvalidArgument") {
return nil
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

why else?

} else {
return err
}
} else if err == io.EOF {
Copy link
Contributor

Choose a reason for hiding this comment

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

why else?

return nil
for {
_, err := gnsiCStream.Recv()
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

could this be a swith err {} instead of this chain or else/if/etc?

msg, err := mStream.Recv()
if err == io.EOF {
return nil
} else if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

why else? why not just switch on err ?
chains of tihs if/else/elseif/etc are toilsome to think though, when all you are relaly doing is a switch statement.

(also see previous comment about adminishment in golang for use of else generally)

@coveralls
Copy link

Pull Request Test Coverage Report for Build 11359918104

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 55.268%

Totals Coverage Status
Change from base Build 11359443484: 0.0%
Covered Lines: 1983
Relevant Lines: 3588

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants