ServerFuzzingRegressionTests.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 GRPC
  18. import NIOCore
  19. import NIOEmbedded
  20. import XCTest
  21. import struct Foundation.Data
  22. import struct Foundation.URL
  23. final class ServerFuzzingRegressionTests: GRPCTestCase {
  24. private static let failCasesURL = URL(fileURLWithPath: #filePath)
  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. try! channel.connect(to: try! SocketAddress(ipAddress: "127.0.0.1", port: 0)).wait()
  33. defer {
  34. _ = try? channel.finish()
  35. }
  36. let configuration = Server.Configuration.default(
  37. target: .unixDomainSocket("/ignored"),
  38. eventLoopGroup: channel.eventLoop,
  39. serviceProviders: [EchoProvider()]
  40. )
  41. XCTAssertNoThrow(try channel._configureForServerFuzzing(configuration: configuration))
  42. // We're okay with errors. Crashes are bad though.
  43. _ = try? channel.writeInbound(buffer)
  44. channel.embeddedEventLoop.run()
  45. }
  46. private func runTest(withInputNamed name: String) throws {
  47. let url = ServerFuzzingRegressionTests.failCasesURL.appendingPathComponent(name)
  48. let data = try Data(contentsOf: url)
  49. let buffer = ByteBuffer(data: data)
  50. self.runTest(withInput: buffer)
  51. }
  52. func testFuzzCase_debug_4645975625957376() {
  53. let name = "clusterfuzz-testcase-minimized-grpc-swift-fuzz-debug-4645975625957376"
  54. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  55. }
  56. func testFuzzCase_release_5413100925878272() {
  57. let name = "clusterfuzz-testcase-minimized-grpc-swift-fuzz-release-5413100925878272"
  58. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  59. }
  60. func testFuzzCase_release_5077460227063808() {
  61. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5077460227063808"
  62. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  63. }
  64. func testFuzzCase_release_5134158417494016() {
  65. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5134158417494016"
  66. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  67. }
  68. func testFuzzCase_release_5448955772141568() {
  69. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5448955772141568"
  70. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  71. }
  72. func testFuzzCase_release_5285159577452544() {
  73. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5285159577452544"
  74. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  75. }
  76. func testFuzzCase_release_4739158818553856() {
  77. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-4739158818553856"
  78. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  79. }
  80. }