ServerFuzzingRegressionTests.swift 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2021, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import EchoImplementation
  17. import struct Foundation.Data
  18. import struct Foundation.URL
  19. import GRPC
  20. import NIOCore
  21. import NIOEmbedded
  22. import XCTest
  23. final class ServerFuzzingRegressionTests: GRPCTestCase {
  24. private static let failCasesURL = URL(fileURLWithPath: #file)
  25. .deletingLastPathComponent() // ServerFuzzingRegressionTests.swift
  26. .deletingLastPathComponent() // GRPCTests
  27. .deletingLastPathComponent() // Tests
  28. .appendingPathComponent("FuzzTesting")
  29. .appendingPathComponent("FailCases")
  30. private func runTest(withInput buffer: ByteBuffer) {
  31. let channel = EmbeddedChannel()
  32. defer {
  33. _ = try? channel.finish()
  34. }
  35. let configuration = Server.Configuration.default(
  36. target: .unixDomainSocket("/ignored"),
  37. eventLoopGroup: channel.eventLoop,
  38. serviceProviders: [EchoProvider()]
  39. )
  40. XCTAssertNoThrow(try channel._configureForServerFuzzing(configuration: configuration))
  41. // We're okay with errors. Crashes are bad though.
  42. _ = try? channel.writeInbound(buffer)
  43. channel.embeddedEventLoop.run()
  44. }
  45. private func runTest(withInputNamed name: String) throws {
  46. let url = ServerFuzzingRegressionTests.failCasesURL.appendingPathComponent(name)
  47. let data = try Data(contentsOf: url)
  48. let buffer = ByteBuffer(data: data)
  49. self.runTest(withInput: buffer)
  50. }
  51. func testFuzzCase_debug_4645975625957376() {
  52. let name = "clusterfuzz-testcase-minimized-grpc-swift-fuzz-debug-4645975625957376"
  53. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  54. }
  55. func testFuzzCase_release_5413100925878272() {
  56. let name = "clusterfuzz-testcase-minimized-grpc-swift-fuzz-release-5413100925878272"
  57. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  58. }
  59. func testFuzzCase_release_5077460227063808() {
  60. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5077460227063808"
  61. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  62. }
  63. func testFuzzCase_release_5134158417494016() {
  64. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5134158417494016"
  65. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  66. }
  67. func testFuzzCase_release_5448955772141568() {
  68. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5448955772141568"
  69. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  70. }
  71. func testFuzzCase_release_5285159577452544() {
  72. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5285159577452544"
  73. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  74. }
  75. }