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

[TT-13657]: Add protocol and port to oas #6846

Merged
merged 4 commits into from
Jan 27, 2025
Merged

[TT-13657]: Add protocol and port to oas #6846

merged 4 commits into from
Jan 27, 2025

Conversation

kofoworola
Copy link
Contributor

@kofoworola kofoworola commented Jan 24, 2025

User description

TT-13657
Summary [OAS] Granular control over client>gateway HTTP
Type Story Story
Status In Dev
Points N/A
Labels -

Description

TT-13657

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

PR Type

Enhancement, Tests


Description

  • Added protocol and port fields to the Server struct.

  • Updated JSON schema to include protocol and port definitions.

  • Enhanced tests to validate protocol and port functionality.

  • Removed unused fields from migration tests.


Changes walkthrough 📝

Relevant files
Tests
linter_test.go
Add default `protocol` value in linter test                           

apidef/oas/linter_test.go

  • Added a default value for the protocol field in test settings.
+1/-0     
oas_test.go
Remove unused fields from migration tests                               

apidef/oas/oas_test.go

  • Removed ListenPort and Protocol from the list of non-migrated fields.
  • +0/-2     
    server_test.go
    Add tests for `protocol` and `port` in Server                       

    apidef/oas/server_test.go

  • Added test cases for protocol and port functionality.
  • Enhanced test structure with sub-tests.
  • +28/-8   
    Enhancement
    server.go
    Add `protocol` and `port` fields to Server struct               

    apidef/oas/server.go

  • Added protocol and port fields to the Server struct.
  • Updated Fill and ExtractTo methods to handle protocol and port.
  • +13/-0   
    x-tyk-api-gateway.json
    Update JSON schema with `protocol` and `port` definitions

    apidef/oas/schema/x-tyk-api-gateway.json

  • Added protocol and port definitions to the JSON schema.
  • Defined valid values for the protocol field.
  • +11/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @buger
    Copy link
    Member

    buger commented Jan 24, 2025

    Knock Knock! 🔍

    Just thought I'd let you know that your PR title and story title look quite different. PR titles that closely resemble the story title make it easier for reviewers to understand the context of the PR.

    An easy-to-understand PR title a day makes the reviewer review away! 😛⚡️
    Story Title [OAS] Granular control over client>gateway HTTP
    PR Title [TT-13657]: Add protocol and port to oas

    Check out this guide to learn more about PR best-practices.

    Copy link
    Contributor

    github-actions bot commented Jan 24, 2025

    API Changes

    --- prev.txt	2025-01-27 10:17:58.088197873 +0000
    +++ current.txt	2025-01-27 10:17:53.220165159 +0000
    @@ -3820,6 +3820,14 @@
     	//
     	// Tyk classic API definition: `allowed_ips` and `blacklisted_ips`.
     	IPAccessControl *IPAccessControl `bson:"ipAccessControl,omitempty" json:"ipAccessControl,omitempty"`
    +	// Protocol configures the HTTP protocol used by the API.
    +	// Possible values are:
    +	// - "http": Standard HTTP/1.1 protocol
    +	// - "http2": HTTP/2 protocol with TLS
    +	// - "h2c": HTTP/2 protocol without TLS (cleartext).
    +	Protocol string `bson:"protocol,omitempty" json:"protocol,omitempty"`
    +	// Port Setting this value will change the port that Tyk listens on. Default: 8080.
    +	Port int `bson:"port,omitempty" json:"port,omitempty"`
     }
         Server contains the configuration that sets Tyk up to receive requests from
         the client applications.

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Possible Issue

    The Protocol and Port fields were added to the Server struct. Ensure that these fields are properly validated and handled in all relevant parts of the codebase to avoid potential misconfigurations or runtime errors.

    // Protocol configures the HTTP protocol used by the API.
    // Possible values are:
    // - "http": Standard HTTP/1.1 protocol
    // - "http2": HTTP/2 protocol with TLS
    // - "h2c": HTTP/2 protocol without TLS (cleartext).
    Protocol string `bson:"protocol" json:"protocol"`
    // Port Setting this value will change the port that Tyk listens on. Default: 8080.
    Port int `bson:"port" json:"port"`
    Test Coverage

    New test cases were added for Protocol and Port in the Server struct. Verify that these tests cover all edge cases and scenarios, including invalid values.

    t.Run("empty", func(t *testing.T) {
    	t.Parallel()
    
    	var emptyServer Server
    
    	var convertedAPI apidef.APIDefinition
    	convertedAPI.SetDisabledFlags()
    	emptyServer.ExtractTo(&convertedAPI)
    
    	var resultServer Server
    	resultServer.Fill(convertedAPI)
    
    	assert.Equal(t, emptyServer, resultServer)
    })
    
    t.Run("port protocol", func(t *testing.T) {
    	var server = Server{
    		Port:     3000,
    		Protocol: "http",
    	}
    	var convertedAPI apidef.APIDefinition
    	var resultServer Server
    
    	server.ExtractTo(&convertedAPI)
    
    	assert.Equal(t, server.Port, convertedAPI.ListenPort)
    	assert.Equal(t, server.Protocol, convertedAPI.Protocol)
    
    	resultServer.Fill(convertedAPI)
    	assert.Equal(t, server, resultServer)
    })

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Add tests for protocol and port validation

    Add test cases to verify that invalid Protocol values are rejected and that the Port
    field enforces a valid range.

    apidef/oas/server_test.go [28-42]

    -t.Run("port protocol", func(t *testing.T) {
    +t.Run("port protocol validation", func(t *testing.T) {
         var server = Server{
             Port:     3000,
             Protocol: "http",
    +    }
    +    var invalidServer = Server{
    +        Port:     -1,
    +        Protocol: "invalid",
         }
         var convertedAPI apidef.APIDefinition
         var resultServer Server
     
         server.ExtractTo(&convertedAPI)
    -
         assert.Equal(t, server.Port, convertedAPI.ListenPort)
         assert.Equal(t, server.Protocol, convertedAPI.Protocol)
     
         resultServer.Fill(convertedAPI)
         assert.Equal(t, server, resultServer)
    +
    +    // Add assertions for invalid cases
    +    assert.Panics(t, func() { invalidServer.ExtractTo(&convertedAPI) })
     })
    Suggestion importance[1-10]: 7

    Why: The suggestion proposes adding test cases to validate the Protocol and Port fields, which is relevant and actionable. The improved code includes meaningful test cases for invalid values, enhancing the robustness of the PR. However, the suggestion could be more impactful if it also addressed the lack of validation logic in the implementation.

    7

    apidef/oas/linter_test.go Outdated Show resolved Hide resolved
    @kofoworola kofoworola enabled auto-merge (squash) January 27, 2025 10:17
    @kofoworola kofoworola merged commit b6fe04b into master Jan 27, 2025
    28 of 41 checks passed
    @kofoworola kofoworola deleted the fix/TT-13657 branch January 27, 2025 10:38
    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.

    3 participants