ServerFuzzingRegressionTests.swift 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 NIO
  21. import XCTest
  22. final class ServerFuzzingRegressionTests: GRPCTestCase {
  23. private static let failCasesURL = URL(fileURLWithPath: #file)
  24. .deletingLastPathComponent() // ServerFuzzingRegressionTests.swift
  25. .deletingLastPathComponent() // GRPCTests
  26. .deletingLastPathComponent() // Tests
  27. .appendingPathComponent("FuzzTesting")
  28. .appendingPathComponent("FailCases")
  29. private func runTest(withInput buffer: ByteBuffer) {
  30. let channel = EmbeddedChannel()
  31. defer {
  32. _ = try? channel.finish()
  33. }
  34. let configuration = Server.Configuration.default(
  35. target: .unixDomainSocket("/ignored"),
  36. eventLoopGroup: channel.eventLoop,
  37. serviceProviders: [EchoProvider()]
  38. )
  39. XCTAssertNoThrow(try channel._configureForServerFuzzing(configuration: configuration))
  40. // We're okay with errors. Crashes are bad though.
  41. _ = try? channel.writeInbound(buffer)
  42. channel.embeddedEventLoop.run()
  43. }
  44. private func runTest(withInputNamed name: String) throws {
  45. let url = ServerFuzzingRegressionTests.failCasesURL.appendingPathComponent(name)
  46. let data = try Data(contentsOf: url)
  47. let buffer = ByteBuffer(data: data)
  48. self.runTest(withInput: buffer)
  49. }
  50. func testFuzzCase_debug_4645975625957376() {
  51. let name = "clusterfuzz-testcase-minimized-grpc-swift-fuzz-debug-4645975625957376"
  52. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  53. }
  54. func testFuzzCase_release_5413100925878272() {
  55. let name = "clusterfuzz-testcase-minimized-grpc-swift-fuzz-release-5413100925878272"
  56. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  57. }
  58. func testFuzzCase_release_5077460227063808() {
  59. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5077460227063808"
  60. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  61. }
  62. func testFuzzCase_release_5134158417494016() {
  63. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5134158417494016"
  64. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  65. }
  66. func testFuzzCase_release_5448955772141568() {
  67. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5448955772141568"
  68. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  69. }
  70. func testFuzzCase_release_5285159577452544() {
  71. let name = "clusterfuzz-testcase-minimized-ServerFuzzer-release-5285159577452544"
  72. XCTAssertNoThrow(try self.runTest(withInputNamed: name))
  73. }
  74. }